Skip to content

Instantly share code, notes, and snippets.

@Overbryd
Created January 24, 2012 09:58
Show Gist options
  • Save Overbryd/1669348 to your computer and use it in GitHub Desktop.
Save Overbryd/1669348 to your computer and use it in GitHub Desktop.
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
@paskal
Copy link

paskal commented Nov 13, 2014

@hirokiosame, thanks a lot! Just what I was looking for — editing /private/etc/paths don't work with zsh.

@ShivangiM
Copy link

I am on MACOX10.11.6 and did change my paths as mention above, restarted my terminal but I still get default python instead of homebrew python

@lizixroy
Copy link

Hi ShivangiM, I am having the same issue that system python is used despite that I put /usr/local/bin before /usr/bin in my /etc/paths file. Did you solve this issue?

@mcandre
Copy link

mcandre commented Dec 19, 2017

I am unable to modify /etc/paths in macOS 10.13 High Sierra. I am using sudo, my user is a member of the wheel group, SIP is disabled, and the file has chmod 0644 permissions. Yet all attempts to modify the file result in Permission denied for some reason.

@theeternalsw0rd
Copy link

@mcandre, maybe the file is locked. Try sudo chflags nouchg /etc/paths before editing.

@pratyushtewari
Copy link

my philosophy about $PATH is that local paths should always come first,

@teleservices yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment