What is the Unix PATH variable and how do I add to it?
Solution 1:
The UNIX path is an environment variable which is a list of directories in which to look for programs that you're trying to run. It allows you to avoid having to use the complete pathname for running things like /bin/ls
(for example by putting /bin
in the path).
For example, a path may consist of:
/bin:/usr/bin:/usr/sbin
and that means, when you type in the command xyzzy
, it will try to run the first file it finds from the current list:
/bin/xyzzy
/usr/bin/xyzzy
/usr/sbin/xyzzy
(it may skip non-executable files if it's being clever).
You can add things to the path with a command like:
set PATH=/directory/to/add:$PATH:/low/priority/path
which places /directory/to/add
at the start of the path search list, and /low/priority/path
at the end.
However, this usually only changes for the current shell. If you want to make a change in every shell, you should add that line to one of your startup files, like $HOME/.profile
or /etc/profile
. The correct file to use depends on your shell itself and how you've set up the startup files. It's not always easy to tell where it should go but the rules are generally explained in the manpage for whatever shell you're using.
You can usually find a command in the path with one of:
which cmd
whence cmd
to locate the cmd
executable. For example, on my Debian system, I get the following transcript:
pax> which ls
/bin/ls
pax> which firefox
/usr/bin/firefox
pax> which xyzzy
pax>
Solution 2:
What is?
The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command.
How to set it?
PATH=$PATH:/your/directory
export PATH
How can I make it stay on the PATH every time I open the Terminal?
Put the previous two lines inside ~/.bash_profile
(if you are using bash
for the Terminal).
Solution 3:
PATH is a environment variable for unix like systems.
set path:
export PATH=$PATH:<your path>
unset path:
unset $PATH
set path permanently
in your home folder, enable View --> Show Hidden Files.... pen .bash_profile file, before export PATH line, add this line.....
PATH=$PATH:<yourpath>
logout and login again...... check if its working ... well ! it should work.....