Setting variables in /etc/environment not having an affect but setting them in command line is
Put the export SPARK_HOME=...
etc. commands in the startup files of your shell. With bash, that would be either ~/.profile
or ~/.bash_profile
.
On Linux, /etc/environment
is usually read by pam_env.so
during login, and it doesn't support expanding existing variables, so setting PATH=$PATH:/something
will result in the literal string $PATH
to appear in your PATH
. This isn't what you want. (See e.g. this and this, also for fun this.)
Also, setting PATH
in /etc/environment
might not work, since the global startup scripts for the shell might rewrite them. (They do on Debian by default, on the old CentOS I have handy, the startup scripts only seem to prepend to PATH
).
If your system doesn't use pam_env.so
, but you only source the script by hand, then these considerations don't matter, of course. But it looks like it's widely used by at least a couple of Linux distributions, so it might be a good idea to use another filename.
(Because this is completely opposite to what the other answers said, I tested it on an old CentOS.)
I put the following in /etc/environment
:
export FOO1=bar
export FOO2=foo:$FOO
After logging in again, set | grep FOO
shows:
FOO1=bar
FOO2='foo:$FOO'