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

9,393

Solution 1

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.

Solution 2

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
Share:
9,393
o_o_o--
Author by

o_o_o--

Updated on September 18, 2022

Comments

  • o_o_o--
    o_o_o-- over 1 year

    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.

    • Admin
      Admin over 11 years
      Have you verified that git is actually in /usr/local/bin?
    • Admin
      Admin over 11 years
      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".
  • Joe Bane
    Joe Bane over 11 years
    Run ls -l /usr/local/bin/git too. I bet it is a symbolic link to /usr/bin/git.
  • Joe Bane
    Joe Bane over 11 years
    Oh, and /usr/local/git/bin appears to be where the official installer puts it too.
  • Joe Bane
    Joe Bane over 11 years
    You should look at /etc/paths and /etc/paths.d as well.
  • o_o_o--
    o_o_o-- over 11 years
    here'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 :)
  • Joe Bane
    Joe Bane over 11 years
    That's ... odd. Glad you're up and running now at least.