How to Set the PATH in Ubuntu

Techwalla may earn compensation through affiliate links in this story.

The PATH environment variable in Ubuntu, as well as all other forms of Linux and Unix, is used to define the locations where the system looks for installed programs. Directory paths such as "/usr/bin" and "/usr/sbin" are already defined in the PATH, but if users want to define other directories, such as a "/home/USER/bin" directory, to allow each user to install his own set of programs, they can do so easily.


Step 1

Open the terminal by clicking "Applications," "Accessories" and "Terminal."

Video of the Day

Step 2

Type the following command into the terminal to define a new PATH:

PATH=$PATH:/home/USER/bin export PATH


This will append the directory "/home/USER/bin" to the end of the PATH variable. The order of the directories in the PATH variable matters; the order of the directories is the order in which Ubuntu will look for programs.

Unfortunately, this change takes effect only so long as the current terminal is open.


Step 3

Type one of the following to edit the "profile" configuration file that defines commands to be run every time the terminal is started:

nano ~/.bash_profile sudo nano /etc/profile


The first will edit the profile of the current user and the changes will take effect only for that user. The latter will alter the profile for the entire system and the changes will take effect for all users. Since this is potentially dangerous, it requires the "super user do" (sudo) command and will prompt you for an administrator's password.


Step 4

Add the first line from Step 2 to the text file and save your work. The changes will take effect as soon as you restart the terminal program.