LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   permanently store PATH variables (https://www.linuxquestions.org/questions/linux-newbie-8/permanently-store-path-variables-655267/)

hiteshthappa 07-12-2008 04:32 AM

permanently store PATH variables
 
Hi can anyone plz tell me how do i store my PATH variables permanently.
I know thats its something to do with .bash_profile file. but i dont no how how to modify it.
:scratch:

reddazz 07-12-2008 04:34 AM

You edit the file using a text editor and add something like
Code:

export PATH=$PATH:/new/path/bin

jschiwal 07-12-2008 04:38 AM

Add two lines like:
PATH=$PATH:/usr/local/bin
export PATH

This example is for adding /usr/local/bin to PATH.

You might want to check which bash startup variable your distro uses. If there is already a .profile but not a .bash_profile, then use the .profile file instead. My only concern is that .bash_profile will be sourced instead of .profile, missing things added by your .profile command. However, if there is no .profile file in your home directory, go ahead and use .bash_login.

The bash info manual explains which startup scripts are searched for when bash starts up. You probably already read through that.

stress_junkie 07-12-2008 08:20 AM

Quote:

Originally Posted by jschiwal (Post 3212017)
You might want to check which bash startup variable your distro uses. If there is already a .profile but not a .bash_profile, then use the .profile file instead. My only concern is that .bash_profile will be sourced instead of .profile, missing things added by your .profile command. However, if there is no .profile file in your home directory, go ahead and use .bash_login.

Or to put it another way, different distributions use different startup scripts. You may have to experiment to find the ones that your distribution uses.

The following files are a good bet:

/etc/bashrc
/etc/profile
/etc/profile.d/*

Distributions that I've used are very unreliable about running the files in the $HOME directory at login.

$HOME/.bashrc
$HOME/.profile
$HOME/.alias

On the other hand the files in the /etc directory are likely to be overwritten by a patch or an upgrade.

jschiwal 07-15-2008 08:59 PM

Just a note:
The /etc/profile startup script is for the entire system and not suited for changing your path. In SuSE, you shouldn't edit it at all but edit /etc/profile.local instead. There are also scripts in /etc/profile.d/. This allows an installation program to change global configurations by dropping a script in there. That way the config program can leave the /etc/profile script alone. On some systems that use selinux or apparmour, they may be prohibited from modifying /etc/profile anyway.

The ~/.aliases or ~/.alias file might be sourced by your startup script. It is alway a good idea to actually read your startup scripts to see what get's sourced. Often there is a line that first checks for a scripts existance, and only if it exists runs it. The "if [ -x ..." blocks will name these scripts, and reading ~/.profile or /etc/profile would be a good way to discover others (which may be just for your distro).


All times are GMT -5. The time now is 09:04 PM.