0

How to add a directory to the $PATH in Ubuntu?

How do I add a directory to the $PATH in Ubuntu and make the changes permanent?

PATH Ubuntu Add a comment
beulah
asked Jan 25 2019

Answer

0

let us start by first outputting the content of $PATH variable:

$ echo $PATH

And you'll get the result something like this which is a list of directories separated by colon:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Now here comes the important part to make your terminal programs executable without writing full path.

  1. Exporting PATH variable to /etc/environment
    One of the fastest way to permanently add directory to $PATH environment variable is by using the following command:

#first append the new directory to path

$ PATH = /usr/local/sbin:/usr/local/bin:/pathToMyDirectory
$ source /etc/environment && export PATH

(OR)

  1. Using ~/.profile file
    Another way is use the .profile file by adding the export command and then run the source command:
    #add this command to ~/.profile file
    $ export PATH=$PATH:/myNewDir
    #then run the source command
    $ source ~/.profile
    Here $PATH refers to content already set by system, so that we don't have to write previous directories path.
Add a comment
linuxhelp
asked Jan 25 2019
Post your Answer