Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to permanently set $PATH on Linux/Unix [closed]

On Linux, how can I add a directory to the $PATH so it remains persistent across different sessions?

Background

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?

like image 928
Ali Avatar asked Feb 01 '13 00:02

Ali


People also ask

How do I unset a PATH variable in Linux?

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.

How do I permanently set PATH in Centos 7?

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.


1 Answers

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 
like image 100
mpowered Avatar answered Sep 28 '22 23:09

mpowered