04 May 2014
How To Use Homebrew's Version of Git
If you’re using Homebrew with OSX, chances are you have multiple copies of the same software packages living on your machine. With this in mind, it’s important to know which version of a particular package gets run when you type a command at the command line. For example, when you type
git status, are you running OSX’s version of git or Homebrew’s version?
Here’s the scoop:
OSX’s binaries live in
/usr/bin. They are the defaults that either came
preinstalled in your machine, or were bundled with Xcode.
$ ls /usr/bin
Under the covers, Homebrew installs packages or ‘kegs’ in their own directories in
$ ls /usr/local/Cellar
For convenience, Homebrew symlinks binaries nested within these directories to
/usr/local/bin. These links are how you access and run Homebrew binaries.
$ ls /usr/local/bin
When you have an OSX version of a package AND a homebrew version, precedence is determined by your PATH variable.
$ which git /usr/bin/git
If you take a look at your global PATH configuration by running
cat etc/paths you’ll see that binaries in
run before binaries in
/usr/local/bin by default.
$ cat etc/paths /usr/bin /bin /usr/sbin /sbin /usr/local/bin
You can move Homebrew’s binaries to the front of the line by adding this
to your preferred shell’s resource file (
$ which git /usr/local/bin/git