LINUX BASICS: THE $PATH VARIABLE

created: 25.10.2018 10:13

edited: 30.10.2018 08:48

back

PATH is a special environment variable. The "full path" to a file represents its exact location on the filesystem, such as /usr/bin/bash. Any time you type the name of a program without a full path, bash searches your PATH to find it. Here's a simple example of PATH:

bash
/home/user/pythons/27/bin:/usr/local/bin:/usr/bin:/bin

The PATH is searched from left to right, with : as a separator. So when I type python in my terminal, bash will look in the following places (in order) to find it:

text
/home/user/pythons/27/bin
/usr/local/bin
/usr/bin
/bin

You can also define relative PATH pathes, like:

text
./vendor/bin

Modifying your PATH
The safest way to add something to your path is to append it. Note that you do not name the executable itself in the path, just the folder that it sits in.

bash
export PATH=$PATH:/opt/python33