I'm trying to add a directory to my path so it will always be in my Linux path. I've tried:
export PATH=$PATH:/path/to/dir
This works, however each time I exit the terminal and start a new terminal instance, this path is lost, and I need to run the export command again.
How can I do it so this will be set permanently?
the best simple way is the following line:
PATH="<directory you want to include>:$PATH"
in your .bashrc file in home directory.
It will not get reset even if you close the terminal or reboot your PC. Its permanent
I stumbled across this question yesterday when searching for a way to add a folder containing my own scripts to the PATH - and was surprised to find out that my own
~/.profile
file (on Linux Mint 18.1) already contained this:Thus, all I had to do was create the folder
~/bin
and put my scripts there.In Ubuntu, edit
/etc/environment
. Its sole purpose is to store Environment Variables. Originally the $PATH variable is defined here. This is a paste from my/etc/environment
file:So you can just open up this file as root and add whatever you want.
For Immediate results, Run (try as normal user and root):
UPDATE:
If you use
zsh
(a.k.a Z Shell), add this line right after the comments in/etc/zsh/zshenv
:I encountered this little quirk on Ubuntu 15.10, but if your zsh is not getting the correct PATH, this could be why
the files where you add the export command depends if you are in login-mode or non-login-mode.
if you are in login-mode, the files you are looking for is either /etc/bash or /etc/bash.bashrc
if you are in non-login-mode, you are looking for the file /.profile or for the files within the directory /.profiles.d
the files mentioned above if where the system variables are.
Permanently add PATH variable
Global:
Local(for user only):
For global restart. For local relogin.
Example
Before:
After:
Alternatively you can just edit profile:
Another way(thanks gniourf_gniourf):
For debian distribution, you have to: