Wednesday, December 16, 2009

How to add a directory to the path?

 

Sometimes you may need to add a directory to the Linux PATH, and the reason to do this, could be to have some scripts you may have written included in the execution PATH.

This is done easily by with a single command line, but that is going to last only until you reboot the machine or, if logout and loggin again, so If you want to make it permanent, you may need to edit some config files, there is one global, and there are also specific ones for each user, you may choose which according to your needs.

Add a directory to the PATH only for this session

To do this, just run this command from the shell.

export PATH=$PATH:/new/directory

Or

export PATH=/new/directory:$PATH

Add a directory to the PATH of your user only

Just add one of the above commands to the .bash_profile file, if you are using bash, you will have to choose the appropriate one if you are using another shell, you may also add these two lines instead of the above one

PATH=$PATH:/new/directory

export PATH

Add a directory to the PATH globally

To do this, you will have to edit the /etc/profile file, (you will have to be root to do that), and find this line.

PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/share/bin"

And add your directory there.

 
Things You Should Know About Linux !!!