Setting variables in /etc/environment not having an affect but setting them in command line is

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 pyspark

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. 

Replay

Put the export SPARK_HOME=... etc. commands in the startup files of your shell. With bash, that would be either ~/.profile or ~/.bash_profile.



/etc/environment is 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 distributions.



(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'

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).

If you cat /etc/environment you'll see the line doesn't look right.

Instead, use

echo 'export PATH="$SPARK_HOME/bin:$PATH"' >> /etc/environment

This will use the values of $SPARK_HOME and $PATH in place when you source the file.

Category: centos Time: 2016-07-29 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.204 (s). 12 q(s)