Linux - How to set the $PATH environment variable?

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix

1 - About

The $PATH environment variable is a list of which directories Linux will search for for executable files.

As in DOS, the shell uses the PATH variable to locate a command. PATH contains a list of directories separated by colons: When you enter a command, the shell search it in each of the directories specified in the PATH value trying to find it.

If it can't find it, you'll see a “Command not found” message.

Advertising

3 - How

3.1 - to Manage it?

To manipulate and to change it, refer to this article: Bash - (Environment) Variable. Below is simple snippet.

3.2 - See it

[[email protected] lib]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

3.3 - See if a command is in your path

To see if a command is in your path, you can use the which command:

$ which mycommand

3.4 - Change it for the session scope

To change your PATH variable to include a directory in a session scope:

[[email protected] lib]# export PATH=$PATH:$HOME/bin
[[email protected] lib]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin

You can remark the root bin at the end. It was added.

Of you can add it permanently by adding this line in a shell startup script

3.5 - Docker

  • To set it globally for all users
RUN echo "export PATH=$PATH:/whatever" >> /etc/profile
Advertising

4 - Documentation / Reference

os/linux/path.txt · Last modified: 2018/11/19 16:05 by gerardnico