Cannot correctly set up the PATH environment variable Centos
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Cannot correctly set up the PATH environment variable Centos
I am having troubles with the PATH environment variable. A while ago I installed Java on my system and now I have removed it and I am trying to reinstall. Now the java issue is a separate thing, I would like some help with the environment variables.
I am running Centos 5 x86_64 as shown below:
Code:
[dralexpe@new-screamer ~]$ uname -a
Linux new-screamer.localdomain 2.6.18-53.1.14.el5 #1 SMP Wed Mar 5 11:37:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
I changed the .bash_profile to add the path to the java installation, and to set up the JAVA_HOME variable as follows:
Code:
[dralexpe@new-screamer ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$HOME/32bit_applications/usr/java/jdk1.6.0_03/bin:$PATH
export PATH
JAVA_HOME=$HOME/32bit_applications/usr/java/jdk1.6.0_03
export JAVA_HOME
dmesg > boot.msg
[dralexpe@new-screamer ~]$
I log out and log back in and the environment is still unchanged from what it was before as shown below:
The path has been added, but there is the old path to the java installation which comes first, and which I am not able to remove from the PATH. Also, the JAVA_HOME is not changed also.
Do I need to make a separate script which should be called by .bash_profile?
I seem to remember seeing an issue like this a while ago. Turned out that if you have any xterms open (via the GUI), then it caches the settings you've got and applies them to any new terms you open.
You have to completely logout of all sessions and the GUI.
Iirc, you can test alterations by doing
source .bash_profile
OR
. .bash_profile
OR
create new shell by invoking
bash
I tried to log into a failsafe terminal session, but I still had to run source .bash_profile to get the environment to show the changes.
I guess what I am trying to ask is where should I change the system wide settings such that the PATH is the one I want? Also how can I get rid of some entries in the PATH, such as /usr/java/jdk1.6.0_03/bin?
I know I can do it with shell commands, but I don't want to do this every time I open a shell in the GUI (in my case that's KDE).
You did the right thing originally, you just have to decide if you want ALL users to get the same settings, in which case the file is
/etc/profile
(edit as root)
or just individuals eg yourself, in which case its
$HOME/.bash_profile
I am trying to setup the PATH just for myself, not for all users. The problem that I am having is that the old java path, in my case /usr/java/jdk1.6.0_03/bin, is still in the PATH, and even in duplicate and I don't know how to remove it.
Here is the .bash_profile which I had created:
Code:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
dmesg > boot.msg
#write the PATH before doing anything
echo $PATH > $HOME/pathval.txt
PATH=$(echo $PATH | sed -e 's/\/usr\/java\/jdk1.6.0_03\/bin://g')
export PATH
#write the PATH after doing the removal of entries
echo $PATH >> $HOME/pathval.txt
The way I see it, the PATH variable should match the second entry in the pathval.txt file, but it isn't. Somehow the java path is added back after the .bash_profile is run. Here is what I got:
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Try
Code:
strace -f -o ~/log -s 1024 -x bash -l
. Maybe it will show (strace output will be in log in your home directory, change the name if you have such file already) what files get read and where does it reads the content of JAVA_HOME at all.
Well, I tried strace but the output was not comprehensible for my knowledge and it was also too long to be allowed to post here.
Anyways, it turned that there was a script /etc/profile.d/java.sh which was setting all the environment variables for java, namely JRE_HOME, JAVA_HOME, CLASSPATH then added JAVA_HOME to the PATH.
I disabled those lines in the script and the problem was solved.
I would like to thank a lot to all of you for all your help.
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Well, that is close top what I hoped for - strace was proposed for finding a script that mentions unwanted values of variables. Nice to hear that problem is solved.
By the way (if it will ever be useful, and it may be), there are some nice ways to share a huge chunk of text in a forum. You could check if pastebin.org (or some similar service, there are a few) accepts such amounts of data (which is not entirely unlikely). You could sign up for a free hosting and create one page with <pre> tag and all the needed data; please, use random name not to deprive anyone with a more elaborate site idea of the namespace. Also registering a fresh GMail/Yahoo! Mail, sending the file to yourself and sharing the login and password here (there is only message in the inbox/outbox, as it is a fresh account that should be abandoned afterwise) works.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.