Random Linux

Linux, video games and web hosting

The $PATH variable in Linux is a set of directories that it will look in for executable files when you run a command. To see what is currently in your path, you can run the following command:

[email protected] [~]#echo $PATH

Which should give some output like this:

/usr/local/bin:/bin:/usr/bin:/home/username/bin

If there was a directory that you wanted to be able to run commands out of without using the full path to the directories, you want to add them to your $PATH. To do that, you will want to edit the .bash_profile, which will be found in /home/user if you need to add it for a user that you created or /root if you are wanting to add it to the path for root. So open that file with your favorite text edit editor and add something like this. In this example, we will be adding the path /home/bin.

[email protected][~]#nano /root/.bash_profile

Then under the section that says “User specific environment and startup programs”, you would add the following:

export PATH=$PATH:/root/bin

Then save the file. Now you can make sure that it was added correctly by using echo $PATH again.

[email protected] [~]#echo $PATH

Which should output the same thing but with the newly added path as well.

/usr/local/bin:/bin:/usr/bin:/home/username/bin:/root/bin

Once you do that, you are able to run any executable files that are in that folder without using the full path. For example, if you have test.sh at /root/bin/test.sh, you can just type in test.sh anywhere in the file system and it will run, you will no longer need to type in /root/bin/test.sh.

March 13th, 2011

Posted In: How To

Tags: ,

3 Comments