Linux $PATH Variable Tutorial

Linux provides the $PATH environment variable in order to store the paths or location of the binaries or executables. When a command or executable is called from the shell or application the $PATH environment variable is used to look up the locations. The $PATH variable stores multiple locations which are inspected for the specified command or script.

$PATH Environment Variable

The $PATH is an environment variable whic can be accessed for different shells, programs, scripts etc. The $PATH variable can be in different locations like ~/.bashrc , /etc/login.defs etc. But the most appropriate location is the users home directory .bashrc file.

Get/Display $PATH Environment Variable

The $PATH variable can be listed in different ways. But the most popular, easy and practical way to display the $PATH variable is printing it in the bash shell or terminal. As the $PATH is an environmental variable it can be printed by using the echo command like below.

echo $PATH

The output is very similar in most of the cases.


We can see that the paths are separeted with the : . The “/home/ismail/.local/bin” is the path related with the current user. All other paths are accessable by other users.

Add New Directory To The $PATH Variable

The $PATH environment variable contains multiple locations. When we set a single location all previous locations are lost. So in order to add a new directory or location to the $PATH variable, the new directory is added after the existing $PATH variable. In the following example, we will add the “/mnt/bin” to the existing $PATH variable. Also, the export statement is used to make the new $PATH variable available after now.

export PATH=$PATH:/mnt/bin

Add New Directory To The $PATH Variable Permanently

In the previous step, a new directory is added into the $PATH variable for temporarily. After the system restarted all previous $PATH definitions cleared. In order to make the $PATH variable permanent, it should be put into a configuration file like ~/.bashrc, etc like below.

export PATH=$PATH:/mnt/bin

Leave a Comment