I am setting certain environment variables for the command
pyspark to work. When I set the variables in
/etc/environment and source it, it doesn't work. However, when I set them in command line they do work but ofcourse only for this session. My intent is to set them globally so that even if I re-open the session I can just type
Setting in /etc/environment
[[email protected] ~]# more /etc/environment [[email protected] ~]# echo "export SPARK_HOME=/srv/spark" >> /etc/environment [[email protected] ~]# echo "export PATH="$SPARK_HOME"/bin:"$PATH >> /etc/environment [[email protected] ~]# echo "export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk" >> /etc/environment [[email protected] ~]# source /etc/environment [[email protected] ~]# pyspark --version -bash: pyspark: command not found
Setting on command line
[[email protected] ~]# export SPARK_HOME=/srv/spark [[email protected] ~]# export PATH=$SPARK_HOME/bin:$PATH [[email protected] ~]# export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk [[email protected] ~]# pyspark --version Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 1.6.1 /_/ Type --help for more information.
export SPARK_HOME=... etc. commands in the startup files of your shell. With bash, that would be either
is read by
during login, and it doesn't support expanding existing variables, so setting
will result in the literal
to appear in your
. This isn't what you want. (See e.g. this
, also for fun this
/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
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 distributions.
(Because this is completely opposite to what the other answers said, I tested it on an old CentOS.)
I put the following in
After logging in again,
set | grep FOO shows:
This line doesn't do what you think:
echo "export PATH="$SPARK_HOME"/bin:"$PATH >> /etc/environment
The problem is that
$SPARK_HOME is being evaluated during the
echo (as is
$PATH; you probably don't want your current PATH in that file).
cat /etc/environment you'll see the line doesn't look right.
echo 'export PATH="$SPARK_HOME/bin:$PATH"' >> /etc/environment
This will use the values of
$PATH in place when you
source the file.