Skip to content

Instantly share code, notes, and snippets.

@mycargus
Created May 14, 2015 06:59
Show Gist options
  • Save mycargus/906b4e1591cb56e1aac2 to your computer and use it in GitHub Desktop.
Save mycargus/906b4e1591cb56e1aac2 to your computer and use it in GitHub Desktop.
You shouldn’t.
Homebrew intentionally keeps /usr/local/bin after /usr/bin in the path for maximum compatibility. Reversing the order of these directories in PATH by editing /etc/paths would mean that all programs anywhere on the system, no matter how they were started, will get the Homebrew version of a command. But some may specifically expect Apple’s version, or just not be able to use a newer version, etc.
How to preserve this principle and still get the Homebrew-installed version of git? As the saying goes, all problems can be solved with a layer of indirection (except having too many layers of indirection). — Or in this case, as it turns out, two layers.
Specifically, 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
You could symlink /usr/local/Cellar/git/1.8.2.1/bin/git directly, but then you would have to fix your symlink every time you did a brew upgrade git (directly or indirectly). By symlinking to Homebrew’s fixed-location symlink, you don’t have to worry about it.
So you add a directory to your $HOME so you can add it your PATH so you can symlink to a symlink, and that fixes your problem and puts a smile on Dr Seuss. Yo dawg I herd you like symlinks so we put a path in your PATH so you can symlink while you symlink.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment