DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

How to Set Permanently $PATH on Linux/Unix

You're trying to add a directory to your $PATH so it will always be in your linux $PATH and accessible anywhere.

You can add your 'path' to $PATH with below command:

$ export PATH=$PATH:/path/to/dir
Enter fullscreen mode Exit fullscreen mode

However each time you exit the terminal or start a new terminal instance, or reboot the system this path is lost and you need to run the export command again.

To set it permanently follow one of the two below:

User Wide

This method will effect your 'current user' only. According to your shell, add your path into your .profile, .bash_profile, .zprofile.

For instance, add it to /home/user/.profile or in short ~/.profile:

# ~/.profile

export PATH=$PATH:/path/to/dir
Enter fullscreen mode Exit fullscreen mode

Then source the file to activate the new $PATH:

$ source ~/.profile
Enter fullscreen mode Exit fullscreen mode

Note:

You can add it into .bashrc,.zshrc as well but I do not prefer this method. Since environment variables should be set in ~/.profile.

System Wide

This method will effect all users in your system. It means that if you add path with this method the path will be visible for all users in the system. In order to execute that you have to have root privileges.

Add your 'path' to /etc/profile/:

# /etc/profile

export PATH=$PATH:/path/to/dir
Enter fullscreen mode Exit fullscreen mode

All done!

Top comments (0)