On Linux, how can I add a directory to the $PATH so it remains persistent across different sessions?
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?
Now that you have set many environment variables on your system, you may want to unset some of them if you don't use them anymore. On Linux, there are two ways of unsetting environment variables : by using the unset command or by deleting variable entries into your system files.
Permanently add a directory to $PATHbashrc file of the user you want to change. Use nano or your favorite text editor to open the file, stored in the home directory. At the end of this file, put your new directory that you wish to permanently add to $PATH. Save your changes and exit the file.
You need to add it to your ~/.profile
or ~/.bashrc
file.
export PATH="$PATH:/path/to/dir"
Depending on what you're doing, you also may want to symlink to binaries:
cd /usr/bin sudo ln -s /path/to/binary binary-name
Note that this will not automatically update your path for the remainder of the session. To do this, you should run:
source ~/.profile or source ~/.bashrc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With