How to set your PATH

Posted on March 14th, 2008 in Basics, Linux+ by admin

In Linux systems your PATH is an environment variable that tells the system where to look for applications by default. For instance, when you type “ls”, it calls the ls program in your path. In most cases this is in /usr/bin. But some applications (and it varies per application and per distribution) are not in your default PATH. It may be in /usr/sbin, such as ifconfig is in openSuse and Fedora. You may have a directory of applications you wrote in a subdirectory in your home folder and it can be time consuming to habitually type the full path and you’d like to just type the application name to call it.


To see what is currently in your path you can:

echo $PATH

Example Output:

/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/bin/X11 /usr/games /usr/X11R6/bin

To add that directory to the end of the path, use the following command:PATH=$PATH:/home/username/myapps

if you echo $PATH again you will see that the directory was added to the PATH.

To remove a variable from the PATH.

get the current path string (echo $PATH), copy it into a text editor, remove the part you dont want, copy the new string with the bit you dont want removed, then back on the command line run “export PATH=<new string here>”

For example:

Since we added /home/username/myapps to the path when we :

echo $PATH

We should get:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:/usr/X11R6/bin:/home/username/myapps/

So what we’d need to do is copy all but that last portion into our next command:

export PATH= /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:/usr/X11R6/bin

and now we’re back to our default.

Or for a more permanent solution you can add your path to these files for your user account

You could reset the Path everytime you login or you could add it to the end of the /home/username/.bashrc file. You would use your favorite text editor to open that file and add the following at the end of it:

export PATH=$PATH:/home/username/myapps

Post a comment