MacOS – Paradox in understanding the “order of booting” of programs given by $PATH

bashinstallmacospath

Background

This tutorial on how to "properly install git" on OSX 10.8.5, says:

To run the latest version you need to adjust your shell path so that
/usr/bin/git runs after /usr/local/bin

So add into the path [in my case: ~/.bash_profile] similar to the below and keep what you already
have in the path, each segment is separated by a colon:

export PATH="/usr/local/bin:/usr/bin/git:/usr/bin:/usr/local/sbin:$PATH"

                                   ^ Focus on this

So my understanding is this:

  • when I log in, BASH will give priority to whatever is appended further on the right-hand side of the export PATH=... line
  • $PATH is at the righter-most : delimited entry in the export PATH=... line
  • $PATH contains /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

So… If my assumptions are correct, then surely the tutorial (quoted above) should have looked like:

export PATH="$PATH:/usr/bin/git"

Instead of:

export PATH="/usr/local/bin:/usr/bin/git:/usr/bin:/usr/local/sbin:$PATH"


My questions are:

Is the tutorial wrong? If not, then what of my assumptions are wrong? If my assumptions are not wrong AND the tutorial is not wrong, please explain why…


Note: I am aware this may not really be relevant to OSX 10.8.5, in which case please flag as off-topic to the appropriate Stack Exchange. But AFAIK, my Ubuntu machine has worked fine with ~/.bashrc having stuff like:

export PATH=$PATH:<myProgram1>:<myProgram2>:...

So it may be that BASH behaves differently in OSX? I don't know…

Best Answer

The tutorial is badly worded, one should never include a binary (like /usr/bin/git) into PATH, only directories. A better alternative would be to write

To run the latest version you need to adjust your shell path so that /usr/local/bin is searched before /usr/bin

So if you set PATH to /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin the manually installed version of git will be picked from /usr/local/bin.

PS: Handling of PATH works the same for all Unix-based systems, the various directories are searched for the command from left to right.