Linux – How to make a public variable in Linux that all users would see

environment-variableslinux

I need to have a variable $FOO on the system that contains a string all users could use, but I have no idea how to create one.

The Upstart job is obviously not a solution as from this thread – Is it possible to export env variable via Upstart?

But I have no idea where else I should look, being Windows developer for a very long time.

Best Answer

Adding to the answers already given, other places to set the variable would be:

  • a file under /etc/env.d (shell-independent),
  • /etc/bash/bashrc for bash users,
  • /etc/zshenv or /etc/zprofile or /etc/zshrc or /etc/zlogin for zsh (as per man zsh),
  • other shell-specific config files, described in each shell's manpage under FILES section.
Related Question