Homebrew installation of git won't take precedence over system version (in /usr/bin/)

10

3

OS X (or Xcode) comes bundled with git 1.7.something, but after brew install git (1.8.0), which git keeps returning the old /usr/bin/git.

This is what I get when I echo $PATH right now:

/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin

Shouldn't Homebrew stuff take precedence?

Also, I've no idea where that usr/local/git/bin comes from at the end.

o_o_o--

Posted 2012-11-03T01:32:38.610

Reputation: 274

Have you verified that git is actually in /usr/local/bin? – Joe Bane – 2012-11-03T01:45:02.217

yep. ls /usr/local/bin shows git is there. Brew also confirms that it's installed. I even ran the git uninstaller (both by brew uninstall and using the one that comes with the official git download) and redid brew install git. I keep getting which git = = /usr/bin/git". – o_o_o-- – 2012-11-03T02:00:56.100

2Run which -a git to see if it's finding it at all. – Joe Bane – 2012-11-03T02:04:16.483

Answers

7

Got it. The answer is in your question; brew installs git to /usr/local/git/bin (not /usr/local/bin) but since that's after /usr/bin in your path, you get that one first. My comment for which -a git should have pointed you in this direction.

Joe Bane

Posted 2012-11-03T01:32:38.610

Reputation: 206

1Run ls -l /usr/local/bin/git too. I bet it is a symbolic link to /usr/bin/git. – Joe Bane – 2012-11-03T02:10:54.030

Oh, and /usr/local/git/bin appears to be where the official installer puts it too. – Joe Bane – 2012-11-03T02:13:20.347

You should look at /etc/paths and /etc/paths.d as well. – Joe Bane – 2012-11-03T02:15:06.977

1here's an interesting turn of events: which -a git returns /usr/local/bin/git; /usr/bin/git; /usr/local/bin/git. So I renamed the old git usr/bin/git_old and got it out of the way. Now git --version returns 1.8, proving that brew did install git successfully. -- Again, I renamed /usr/bin/git to its original name... and suddenly it's working properly! I don't know why or how, but renaming /usr/bin/git and running git once seems to have solved the problem. Who knows what the root of the problem was. Thanks anyway :) – o_o_o-- – 2012-11-03T02:18:08.980

That's ... odd. Glad you're up and running now at least. – Joe Bane – 2012-11-03T02:25:10.653

3

I also encountered this issue.

After installing git through homebrew, if you run brew doctor then it will warn you that, as Joe mentioned above, the system is running the old git because its install location comes first.

But, in the same warning, homebrew gives the code to fix it:

$ echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

chorbs

Posted 2012-11-03T01:32:38.610

Reputation: 131

0

It’s been part of my Unix habits to have a ~/bin directory which I put at the start of my PATH. This is one of the first bits in my .bashrc:

case ":$PATH:" in
  *:$HOME/bin:*) ;;     # do nothing if $PATH already contains $HOME/bin
  *) PATH=$HOME/bin:$PATH ;;  # in every other case, add it to the front
esac

With that in place, then selectively making just the Homebrew-managed git take precedence over the system version (instead of every Homebrew-managed binary), and just for your shell sessions (instead of all programs started from anywhere, including GUI programs), is as simple as symlinking it:

ln -s /usr/local/bin/git ~/bin/git

Aristotle Pagaltzis

Posted 2012-11-03T01:32:38.610

Reputation: 488