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.

I'm only vaguely familiar with Unix and the filesystem convention for Macs, so sorry if this is a dumb/easy question.

I've downloaded an application that is a command-line application, and want to put it somewhere where I can run it from the command-line w/o having to type the path explicitly.

1) what are the conventional paths used for something like this? /usr/bin ? (I'm not at my Mac right now so I can't check) Are there different options, one if I want it for all users, one if I want it for just a particular user like my administrator account?

2) or should I put it in its own directory under the Applications directory, and add it to the path? If so, which file controls where the path is set?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

Macs are highly non-standard in this regard. The default $PATH variable for a regular user puts looks like this:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

By putting /usr/local/bin after /usr/bin and /bin, Mac upends the whole system. Normally, you can put something into /usr/local/ (say a second Perl, compiled in some non-standard way), and then a regular user will hit the custom one rather than the system-wide one first. This is good. Users can get variants, but the system stays pure. In any case, you can put things (as is normal) into /usr/local, but if there is something by the same name already in /usr/bin or /bin, that will get found first.

To fix this, you can change the regular user's $PATH by editing the .profile file in the user's home directory. (That file doesn't exist initially, but you can create it easily.) I do that soon after I start any new Mac. Just so you know, if you use MacPorts or Fink, you can get good package management for command line utilities on a Mac. Each has its own pros and cons. I mention it because they both deliberately use non-standard installation locations, so that they can be easily removed root-and-branch. MacPorts uses /opt/local and Fink uses /sw.

share|improve this answer

/usr/local/bin and /usr/local/sbin are well worth adding to your path, as a lot of makefiles for source builds are defaulted to install there.

If you use MacPorts, its worth adding /opt/local/bin and /opt/local/sbin as well.

The best way to do this is to add

export PATH=/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:$PATH

to the .bashrc file in your home directory (which is hidden, so the CLI is the best way to to do this), or, if you want to change the system wide path, add the same line to /etc/bashrc (not hidden), but you will need to sudo to do this. If you don't have a .bashrc in any user's home, you can make one and add this line to it, but remember to change the permissions on the file you create to make it readable by the user in question (obviously not relevant if you're doing it for your own profile).

The $PATH at the end appends the system default path to whatever you put before. Note that the system searches for binaries in the order of paths given, so if you install a binary in /usr/local or /opt/local that is also installed by default on the system, the versions you install will be found first, which can (though rarely) upset things. Worth watching out for.

Good info here.

I should note that the above assumes you are using bash for the shell, which is the default on Tiger (10.4) and Leopard (10.5), but not on earlier systems, which used tcsh instead, which has a different syntax.

Hope that helps...

share|improve this answer
1  
/usr/local/bin is already in a default OS X $PATH (though too late - see my answer). If you use MacPorts, its installer should edit your path as necessary - at least it always has in my experience. That said, it's good for users to know what it's doing (and why). –  Telemachus Jul 17 '09 at 15:13
    
well spotted @Telemachus: whenever I build a Mac for myself, I customise the hell out of the path first thing, so I can never remember what's standard and what's mine! –  avstrallen Jul 17 '09 at 15:15
1  
I know what you're daying about the MacPorts installer customising the paths in .profile, but I have had an occasion in the past when for some reason, I know not what, this failed to stick (which confused the hell out of me for quite a while!)... so since then I tend to wire it in by hand... –  avstrallen Jul 17 '09 at 15:18
    
"which is hidden, so the CLI is the best way to to do this": dumb question, how do you run TextEdit on a file from the command prompt? –  Jason S Jul 17 '09 at 15:32
    
No such thing as a dumb question: use the open command with the filename as an argument and it should open with whatever is set as the default text editor (TextEdit as standard). –  avstrallen Jul 17 '09 at 15:42

I tend to go with /usr/local. Here's a nice explanation why.

share|improve this answer
    
very helpful, thanks! –  Jason S Jul 17 '09 at 14:55
    
Yep, it's pretty much the same as other *nix operating systems in that regard. –  jtbandes Jul 24 '09 at 17:29
2  
Link is broken. –  Chris Nolet Jul 26 '12 at 23:42
    
link works for me –  AJcodez Jun 17 '13 at 7:15

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.