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

04
2013-09
  • Noam Gagliardi

    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.

  • Answers
  • Joe

    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.

  • Aristotle Pagaltzis

    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
    

  • Related Question

    osx - On Mac OS X with HomeBrew, is there any advantage to installing Git via .dmg rather than via HomeBrew?
  • sampablokuper

    If a Mac OS X user already has HomeBrew installed, is there any advantage to installing Git via the .dmg files for OS X linked from the Git download page rather than via HomeBrew?


  • Related Answers
  • Daniel Beck

    IIRC, Git is required for Homebrew to work, so you most likely already have it. Let's ignore that for a while...


    From the installer readme:

    This installs git to /usr/local/git. Root access is required.

    and creates a new directory tree containing bin, lib, share etc. there.

    It also includes some Perl and Python stuff, probably dependencies so it's self-contained. You can use suspicious package to see what's inside.

    There is no real package management, i.e. you likely need to re-download und run the installer for all updates, and the uninstaller is a very short shell script.


    The Homebrew version installs to /usr/local, distributing its files to bin and the other folders there, like any Homebrew-installed program. It's managed by Homebrew and can be uninstalled and upgraded using it. It can also profit from possible dependencies you already installed using Homebrew, saving disk space. Depending on how you set up Homebrew, it might be possible to install/update git without entering the root password.


    I can't see any reason to install git from the dmg. It's more cumbersome to install and upgrade, it's an older version (@slhck is correct), and you already have it if you use Homebrew anyway.

  • slhck

    I don't think there's much of a difference, although running

    brew install git
    

    works unattended and is way faster and easier than

    • navigating to the Git page you linked
    • finding the link for OS X
    • finding the link for your system
    • downloading the .dmg file
    • opening it
    • double clicking the installer app
    • and running through the installer, accepting terms, selecting install location, etc.

    Apart from that, Homebrew currently seems to have Git 1.7.5, whereas the downloadable Git OS X installer only has 1.7.4.4