Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Correcting $PATH in MacOSX 10.7 for homebrew

$PATH in MacOSX 10.7

MacOSX has a truly global path setting that precedes any other setting like ~/.bash_profile. The file /private/etc/paths is a list of pathnames. The order from top to bottom defines the resulting order in the $PATH variable. After loading /private/etc/paths there is a directory /private/etc/paths.d/ with files in the same style. Those are appended to the $PATH variable.

The default content of /private/etc/paths looks like this:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

The resulting $PATH variable looks like this:

$ echo "$PATH"
# => "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"

Homebrew

When using homebrew in its standard way, all your packages end up in /usr/local. This is a problem if you want to install software via homebrew that should replace system default installations.

Git is a good example.

The system default $ /usr/bin/git --version outputs git version 1.7.4.4. Your homebrew installed git (at the time of writing) $ /usr/local/bin/git --version outputs git version 1.7.8.3.

But without changing the default path combination, you end up using system Git instead of homebrew Git.

Correcting $PATH globally

There is various workarounds and fixes for this problem. For example one could tackle this problem for a specific application. TextMate for example allows you to set TM_GIT to a git executable of your choice. But why bothering with application specific settings, when you can fix the problem at its root.

I propose that /usr/local/bin comes before /usr/bin

Here are the contents of my corrected /private/etc/paths. I've moved /usr/local/bin on top.

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
--- /private/etc/paths.old 2012-01-24 10:34:35.000000000 +0100
+++ /private/etc/paths 2012-01-24 10:34:53.000000000 +0100
@@ -1,5 +1,5 @@
+/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
-/usr/local/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment