How to add directory to PATH in Linux

The $PATH environment variable is a list of directories that tells the shell which directories to search for executable files.

To check what directories are in your $PATH list use command:

echo $PATH

To add new directory ~/.local/bin/ to $PATH use command:

export PATH="$HOME/.local/bin:$PATH"

But this change is only temporary and valid only in the current shell session.

To make the change permanent, you need to define the $PATH variable in the shell configuration files. In most Linux distributions when you start a new session, environment variables are read from the following files:

  • Global shell specific configuration files such as /etc/environment and /etc/profile. Use this file if you want the new directory to be added to all system users $PATH.
  • Per-user shell specific configuration files. For example, if you are using Bash, you can set the $PATH variable in the ~/.bashrc file. If you are using Zsh the file name is ~/.zshrc.

In this example, we’ll set the variable in the ~/.bashrc file. Open the file with your text editor and add the following line at the end of it:

nano ~/.bashrc

export PATH="$HOME/.local/bin:$PATH"

Save the file and load the new $PATH into the current shell session using the source command:

source ~/.bashrc

To confirm that the directory was successfully added, print the value of your $PATH by typing:

echo $PATH