Sometimes when I install new software on Linux machine I want to be able to run it from any given directory. I simply do not want to use full path every time I wish to run some of commands. Unfortunately, sometimes this involves manual setting of the PATH variable.
In general, the syntax for setting PATH variable depends on which shell you are using. The most common one is surely BASH. It uses rather simple syntax:
export PATH=/first/path:/second/path:/third/path
Notice that command above will not append current PATH variable but fully reset it to desired value. If you wish to append current value with new directory paths then you can simply use current value of PATH variable:
export PATH=$PATH:/first/path:/second/path
In this case, two paths (first and second) will be added to current PATH variable value.
If you're using tcsh or csh then you will need to use the following syntax:
set PATH = (/first/path /second/path /third/path)
Again, this command will simply set new variable value. To append to existing value, just like in example for BASH, simply use current PATH value in command and then append new paths to it:
set PATH = (PATH /first/path /second/path /third/path)
Of course, since you made this change on-the-fly, it will be valid only until you logout. Next time you log in, system will use your .bashrc / .cshrc file to set appropriate PATH variable value. So, if you want to make this change permanent, simply edit your .bashrc / .cshrc file and update value there.
For bash, by default file is named .bash_profile and is stored here:
- for all system users except root user: /etc/profile
- for single user: /home/directory/of/user
- for root user: /root
In general, the syntax for setting PATH variable depends on which shell you are using. The most common one is surely BASH. It uses rather simple syntax:
export PATH=/first/path:/second/path:/third/path
Notice that command above will not append current PATH variable but fully reset it to desired value. If you wish to append current value with new directory paths then you can simply use current value of PATH variable:
export PATH=$PATH:/first/path:/second/path
In this case, two paths (first and second) will be added to current PATH variable value.
If you're using tcsh or csh then you will need to use the following syntax:
set PATH = (/first/path /second/path /third/path)
Again, this command will simply set new variable value. To append to existing value, just like in example for BASH, simply use current PATH value in command and then append new paths to it:
set PATH = (PATH /first/path /second/path /third/path)
Of course, since you made this change on-the-fly, it will be valid only until you logout. Next time you log in, system will use your .bashrc / .cshrc file to set appropriate PATH variable value. So, if you want to make this change permanent, simply edit your .bashrc / .cshrc file and update value there.
For bash, by default file is named .bash_profile and is stored here:
- for all system users except root user: /etc/profile
- for single user: /home/directory/of/user
- for root user: /root
No comments:
Post a Comment