Skip to main content Skip to navigation

The $PATH variable

$PATH

When opening a program, the system has to "know" where to look. On Linux and similar systems, there is a special environment variable called the path. Like all environment variables, it starts with a $ and can be shown using the echo command.

Do not just attempt to set the path with export (for bash shell) or setenv (for cshell). This will override the current value and the system wont be able to find many utilities until you start a new shell (or restore the path by some other means). Instead, use the command

export PATH=$PATH:[new location]

which appends to the path.

If you manage to clobber or corrupt your path you can start a new shell.

When searching for a program in the path, the system starts from the beginning and uses the first match found. This means that in general you want to add things to the end of the path, or there will be more overhead on finding system commands. The only time you need to prepend is when you want to override a system program.

If you use a particular path often, you can add the export command to your .bash_rc or .bash_profile file (see here for details).

$LD_LIBRARY_PATH

The LD_LIBRARY_PATH is similar to the $PATH but is used to instruct the system where to look for shared library files when a program starts up. As with $PATH, you must add to it and not overwrite it.

$PYTHONPATH

The PYTHONPATH tells Python which directories to search when loading modules and packages. Once again, you should usually add to it, not overwrite it. Usually, you should only have to set this variable if you have deliberately installed Python packages into custom directories. For most purposes, using pip install --user or a similar command is easier. If you need multiple Python environments which use different packages or versions of packages, try virtualenv.