How to add a directory to path environment variable on linux ?

For a temporary solution or for current terminal session we can use the export command to do this. Here in the below example am adding the directory /usr/local/bin  to path environment variable.

# export PATH=$PATH:/usr/local/bin

For a more permanent solution we can  add this to  ~/.bashrc file:


If you don't know how to edit and add in ~/.bashrc file , you can just execute this line in a Terminal which will do the thing for you.

echo "PATH=\$PATH:/usr/local/bin" >> ~/.bashrc

To crossverify if the above command worked succefuly we can use the below command and check if the path is set correctly.

echo $PATH

We should see our directory path as below.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *