Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Many programming tutorials ask users to add something to their PATH but don't explain what it is. The existing resources that explain the PATH to users new to the command line are not very good.

  • What is the Unix PATH variable?

  • I just downloaded a program, then tried to run a command in the terminal and got command not found. What does this have to do with the PATH?

  • I added something to the PATH with this command and then things worked:

    export PATH=/path/to/some/bin:$PATH
    

    ...but then I got command not found again the next time I started my computer. How can I make it stay on the PATH every time I open the Terminal?

  • What's the best way to determine if a program like Git or gcc is already loaded on my computer?

share|improve this question

migrated from stackoverflow.com Dec 11 '12 at 15:57

This question came from our site for professional and enthusiast programmers.

2  
I've read through many of the answers on SO and I haven't found a answer that answers every one of these questions in a way a newbie can understand. I want something I can link new command line users to. It was my hope to add this as community wiki and attach significant bounty to it. –  Kevin Burke Dec 11 '12 at 8:02
3  
I bet I can find 50 hits if I search google for this question. Why can't you? –  trojanfoe Dec 11 '12 at 8:02
2  
And if none of those links points to SO for a question that's qualified to be here, then it should be added here. We want SO to be where Google goes for programming questions. –  paxdiablo Dec 11 '12 at 8:19
    
Please see this MSO post for Kevin's motivations in asking this question. He'll most likely make an edit to clarify how this information is helpful. –  jmort253 Dec 11 '12 at 8:41
1  
@jmort253: Well, he should start doing it quickly. 4/5 close votes. I won't close because I know wants to edit the question, but he better make it quick. –  Madara Uchiha Dec 11 '12 at 9:03
add comment

4 Answers

The UNIX path is an environment variable which is a list of directories in which to look for programs that you're trying to run. It allows you to avoid having to use the complete pathname for running things like /bin/ls (for example by putting /bin in the path).

For example, a path may consist of:

/bin:/usr/bin:/usr/sbin

and that means, when you type in the command xyzzy, it will try to run the first file it finds from the current list:

/bin/xyzzy
/usr/bin/xyzzy
/usr/sbin/xyzzy

(it may skip non-executable files if it's being clever).

You can add things to the path with a command like:

set PATH=/directory/to/add:$PATH:/low/priority/path

which places /directory/to/add at the start of the path search list, and /low/priority/path at the end.

However, this usually only changes for the current shell. If you want to make a change in every shell, you should add that line to one of your startup files, like $HOME/.profile or /etc/profile. The correct file to use depends on your shell itself and how you've set up the startup files. It's not always easy to tell where it should go but the rules are generally explained in the manpage for whatever shell you're using.

You can usually find a command in the path with one of:

which cmd
whence cmd

to locate the cmd executable. For example, on my Debian system, I get the following transcript:

pax> which ls
/bin/ls

pax> which firefox
/usr/bin/firefox

pax> which xyzzy

pax> 
share|improve this answer
1  
Does this question belong on stackoverflow? –  trojanfoe Dec 11 '12 at 8:06
    
@trojanfoe, as much as any shell-related question does, yes, I would think so. It is also a programming language. –  paxdiablo Dec 11 '12 at 8:08
    
I modified the answer to use : as the separator, as that's used on *nix. Windows uses ; (probably because : already has a meaning in C:). –  Joachim Sauer Dec 11 '12 at 8:57
    
Actually, @Joachim, it's possibly more correct to say that a given shell (rather than UNIX itself) has a specific directory separator but you're right for all the ones I use off the top of my head. Thanks for the fix, cheers. –  paxdiablo Dec 11 '12 at 8:59
    
@paxdiablo: yes, I thought about that but I too can't think of any unix shell that doesn't use : (in Java, for example path.separator is always : on *nix). –  Joachim Sauer Dec 11 '12 at 9:01
show 4 more comments

What is?

The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command.

How to set it?

PATH=$PATH:/your/directory
export PATH

How can I make it stay on the PATH every time I open the Terminal?

Put the previous two lines inside ~/.bash_profile (if you are using bash for the Terminal).

share|improve this answer
add comment

PATH is a environment variable for unix like systems.

set path:

export PATH=$PATH:<your path>

unset path:

unset $PATH

set path permanently

in your home folder, enable View --> Show Hidden Files.... pen .bash_profile file, before export PATH line, add this line.....

PATH=$PATH:<yourpath>

logout and login again...... check if its working ... well ! it should work.....

share|improve this answer
1  
Sorry for the downvote, but this is poorly formatted and phrased. Try to avoid excessive use of bold, excessive use of ellipsis ("...") and write full sentences. That should help avoid such downvotes in the future. –  Joachim Sauer Dec 11 '12 at 9:00
1  
@Joachim Sauer why dont you edit the answer? Why do you prefer to downvote it? –  MikroDel Dec 11 '12 at 9:01
1  
@MikroDel: because there are already better, higher-quality answers to this question and downvoting takes less effort. If this where the only answer, I would probably have edited it. Also: although they are usually no fun, downvotes are a legitimate tools (yes, there are up and down arrows next to each question/answer). –  Joachim Sauer Dec 11 '12 at 9:03
1  
edit or post this comment take near the same time, but edit make it better, and help Shantanu Banerjee and other users –  MikroDel Dec 11 '12 at 9:09
    
@MikroDel: so explaining the reasoning behind a downvote doesn't help the user? I think I've been pretty clear on my reasoning and have given practical tips on improving the quality. The only thing your insistence does it reduce my willingness to explain my downvotes (and as you can see in my profile I don't downvote excessively). –  Joachim Sauer Dec 11 '12 at 9:13
show 3 more comments

Take a look at this How to correctly add a path to PATH?

share|improve this answer
4  
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Joachim Sauer Dec 11 '12 at 8:54
    
there was many questions in one. Many simple questions in one - that why I find it OK to post this link. –  MikroDel Dec 11 '12 at 8:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.