Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
How do I change the path that Linux is using? -
The "how to" that I am following is in the June, 2001 Linux Magazine's "newbies" column. In this column, the author suggests modifying the .bash_profile, but doesn't specify which one to alter.
I have experimented with changing the three files I have found, however none of the changes "take":
/etc/skel/.bash_profile
/home/ronsan/.bash_profile
/root/.bash_profile
if it's adding to the global path, you've got to look in /etc/profile, if it's a userpath add it to ~/.bash_profile in the path statement. After each change you've got to execute to make it stick: ". ./etc/profile" or ". ~/.bash_profile".
*The source in skel is added to their new home when users are added. Keep it clean.
*I would strongly advice you to NOT add custom paths to the /root/.bash_profile that users can write in, it is considered bad for your boxes health.
I'm not sure I understand, yet, how to change the PATH environment variable. I have added to the PATH section of my /etc/profile file and also to my /home/.bash_profile. However, when I reboot, nothing changes. I am running Red Hat v7.0 upgraded to the kernel 2.4. Is some other file than those I have mentioned being used by the system to determine the path?
Ok, but you really don't have to reboot to make it work :-]
Say my /etc/profile contains:
PATH=/bin:/sbin:/usr/sbin:/opt
export PATH
Now I want to add a specific path as required by say Netscape, there are two ways.
1. I can add it to the already defined PATH statement if it is just like finding an application in a path, or 2. I can add a separate path if the application requires it to be a known environment variable.
1:
Adding the path my /etc/profile now sez:
PATH=/bin:/sbin:/usr/sbin:/opt:/usr/lib/netscape
export PATH
or
2:
Adding the path my /etc/profile now sez:
PATH=/bin:/sbin:/usr/sbin:/opt
MOZILLA_HOME=/usr/lib/netscape
export PATH MOZILLA_HOME
Execute ". /etc/profile" after changing the path *should* make it work. If it still doesn't please post why you need it, that many be helpfull + errors, if any.
There is something I don't understand about adding to the PATH environment variable string:
Here's my /etc/profile:
if ! echo $PATH | /bin/grep -q "/usr/X11R6/bin" ; then PATH="$PATH:/USR/X11R6/bin"
fi
(export PATH, etc, follows)
I have added the following:
PATH=$PATH:/sbin
Then, after typing
# /etc/profile
(export PATH, etc, follows)
I type
# env
No change
I have followed an article in Linux magazine, and no matter what I try, the PATH does not change. I have followed the advice in this post by Unspawn (recommendation 1, only. Do not understand #2)
and nothing changes.
I would like to have /sbin/ in my PATH, because I use files that reside there often, and would rather not type /sbin/filename every time I need to use a file therein. I am also curious as to why this does not work for me
I'm not certain if I understand exactly what you want, but here goes.
I think this is what you want:
if ! echo $PATH | /bin/grep -q "/usr/X11R6/bin" ; then
PATH=$PATH:/usr/X11R6/bin
fi
PATH=$PATH:/sbin
export PATH
Then type in: . /etc/profile
Now note in the second line of /etc/profile that I deleted the double quotes and I changed USR to usr. I also placed the PATH=$PATH:/sbin before the export line. When you type in the line . /etc/profile , don't forget the period at the begining of the line and the period is followed by a space. This space is important. If it is not there, bash will create a subshell to execute the command and when the subshell is done, all the changes that were made will disappear with it. I hope this works. I've never tried this before. Good luck.
AHA!
The suggestion by linuxcool about about putting the space in the command '. /etc/profile' solved the problem of why the path was never changing. I was not typing the command correcly.
I was also confused by the fact that the PATH changes depending on whether a non-root user or root user is logged on.
Adding to the confusion is the fact that the PATH differs if I login as Root on the login screen or su from a terminal screen.
Also, about logging in from a terminal screen or su to root. When you login from a terminal screen you'll get root's path. When su to root in a user's terminal, you'll get the user's path unless you enter the command su - . The hyphen will ensure that the user's path is changed to root's path. This means that you won't get the ' command not found error ' when trying to execute commands that only root can.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.