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 currently have two versions of the same executable installed on my OSX machine: one sits in usr/bin, and the other is a Macports installation. When I run which, the terminal returns the location to the usr/bin version. Is there a uniform way to change the default installation, or does every application have their own command option for this?

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted

You need to modify the PATH environment variable. This is the standard used to search for executables under Unix.

When something on Unix looks for an application that is given with a relative path (eg: clang rather than /usr/bin/clang), PATH is split on the : character, and then searched in order.

eg: if your PATH is /opt/local/bin:/bin:/usr/bin then clang will look for /opt/local/bin/clang, and if that is missing, /bin/clang, etc.

Technically, every process has their own way to do this - nothing forces them to follow the convention of using $PATH, but it has been that way for long enough that pretty much everything does.

The other consideration is that every process has an environment of it's own - a copy of PATH included in that. That includes launchd, which is what is responsible for the UI and any application launched from that.

So, you can modify this in your shell init scripts (.bash_profile, .bashrc, .profile, etc), but that won't work if, eg, you launch vim or emacs as a GUI application.

You can also modify /etc/paths, or add a file to /etc/paths.d, and that will form part of the standard environment for everything - including every application launched on the Mac. (You need to log out and back in to have that permeate every part of the system, though.)

share|improve this answer
    
To add to Daniel's answer: MacPort's should have appended an export statement in your .profile or .bash_profile-- It will look like this export PATH=/opt/local/bin:/opt/local/sbin:$PATH If that line is not in there, add it and restart terminal. You can also type echo $PATH to see what is currently set in your shell. –  InChargeOfIT Mar 25 '12 at 18:44
    
I get the concept of $PATH, but this doesn't really answer my question, which makes me wonder if it's misguided to start with: My current .profile looks like this:export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:$PATH:/usr/local/git/bi‌​n. However, for example, the default clang installation is in usr/bin. It's not clear to me to how to force the Macports installation to be the default. –  nipponese Mar 25 '12 at 19:40
    
Oh. I updated the answer to reflect how PATH is searched in practice, but: put the directory containing the executables you prefer earlier in PATH. Beyond that, though, there isn't a concept of "default" application at the Unix level like there is at the OSX UI level. It is just "whatever comes first in the path". –  Daniel Pittman Mar 25 '12 at 20:18
add comment

The PATH variable defines where your commands are.

You may modify this variable in your /etc/paths file. You should verify that /usr/bin is before others.

share|improve this answer
add comment

If modifying $PATH is not feasible for whatever reason, you can create an alias that invokes the executable in the appropriate directory.

share|improve this answer
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.