PATH

From LQWiki
Jump to navigation Jump to search

The PATH is an environmental variable which contains a colon-delimited list of directories used by the shell to find (and run) installed programs. A basic PATH is generally declared in your shell's system-wide startup files (/etc/profile).

Note: The following commands assume the bash shell.

Listing your PATH

The value of your PATH variable can be viewed using the 'echo' command:

$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin

Adding a directory to your PATH

To immediately add a directory to your PATH, simply add the directory to your current PATH:

$ export PATH=$PATH:/new/directory

However, this will only apply to your current session. To make the change permanent you need to edit one of your shell startup files. For system-wide, edit /etc/profile. To make the change user-specific, edit ~/.bash_profile.

Note that the order of directories in your PATH is important. If you have two programs with the same name, the program in the directory first in your PATH will be executed.