PDA

View Full Version : Where and how to put a PATH= variable?



neocortex
18th April 2012, 07:46 PM
Hello ALL!
I am trying to put a system-wide PATH= variable, but nothing seems to work.
Firstly, I added a lines in /etc/profile. Somewhere here:


# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
pathmunge /sbin after
fi

Then, I removed these lines, and added sh-script in /etc/profile.d/ with something like (this is what I've found in one post; example is with JDK):


echo 'export JAVA_HOME=/opt/jdk1.5.0_12' > /etc/profile.d/jdk.sh
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile.d/jdk.sh
source /etc/profile.d/jdk.sh

That did not work either. So, I wonder how to put permanent and system-wide PATH=?

Thanks in advance!
PM

sea
25th April 2012, 10:15 AM
I'd suggest to add your PATH variables to your $HOME/.bashrc
If you are required to log in as root in terminal, and do need those paths from root account too, edit the /etc/bashrc with root rights.

Simplest is to directly add them there.
Adding them to /etc/profile.d/script.sh works too, but there is no need to source it from there (loop), as these scripts are read EVERY time you open a terminal, or log in, or something alike.

The simplest, and imho savest, way to add your own PATH, is like the next few lines in ~/.bashrc:

JH=/opt/jdk1.5.0_12
export PATH=$JH:$PATH

Hope this helps.

marriedto51
25th April 2012, 02:03 PM
The way I set system-wide shell settings is to add a script to the /etc/profile.d directory.

I think to do what you want, I would use a text editor to create a new file java-path.sh somewhere in my home directory, which contains

JAVA_HOME=/opt/jdk1.5.0_12
export JAVA_HOME
PATH="$JAVA_HOME/bin:$PATH"


Next, copy this into /etc/profile.d with

su -c 'cp java-path.sh /etc/profile.d/'

Now restart the shell. (Close the current terminal, and open a new one; or log out and in again.) Test that the settings have taken hold with

printenv JAVA_HOME PATH