5

My OS X comes with a version of Git installed in /usr/bin. However, this version is older than the official stable one. I would like to upgrade it.

Can I use Homebrew to upgrade this version? Or would Homebrew install Git in a separate location (and if I do so, how can I ensure that the new version is actually used)?

9

Don't replace, modify or rename the system tools in /usr/bin. There are a number of reasons why this is a bad thing, and you can search for the specific reasons, but to be simple, don't edit the system versions.

Homebrew knows this, and that's why it stores the tools in /usr/local/bin. This version is used instead of the system version since Homebrew requests that its directory be before the system path in the $PATH variable.

Run brew doctor and you'll probably get a message like this:

Warning: /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew. The following tools exist at both paths:

easy_install
easy_install-2.6

Consider amending your PATH so that /usr/local/bin is ahead of /usr/bin in your PATH.

To fix this, either add this to your profile:

export PATH=/usr/local/bin:$PATH

…or add /usr/local/bin to the top of /etc/paths, such as:

/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
3

Homebrew will install tools in /usr/local/bin so that it doesn't mess with the system tools that came pre-installed on your Mac. As grgarside mentioned, it's not recommended to alter the system tools.

Here are more specific and detailed instructions for setting the PATH environment variable, which allows you to list several directories that you want your Mac to search in when looking for executables.

In order to use the latest version of git, or any other tool you installed in /usr/local/bin with Homebrew, you want to tell your Mac to first look in /usr/local/bin before it looks in the default /usr/bin. You do that by defining the PATH in your .bash_profile, which is a file that gets loaded automatically every time you open a new Terminal window.

You can write the PATH to your .bash_profile by running this one-liner from the Terminal:

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

This command takes everything between the single quotes (echo) and adds it (>>) to a file called .bash_profile in your user’s root (or home) directory (~/).

To have these changes take effect, you can either quit and relaunch Terminal, or run this command:

source ~/.bash_profile

If you want to do it all manually, open your .bash_profile with your favorite editor, then add this line to it:

PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

and save it. Then quit and relaunch Terminal.

Unlike grgarside, I do not recommend changing the /etc/paths file, because you would be making a global change, as opposed to a change that only affects your personal .bash_profile, and only while you're in a bash shell.

  • Thanks - Is there a reason why you would recommend editing the variable PATH directly as opposed to adding the relevant lines to /etc/path (as in the other answer)? – Amelio Vazquez-Reina Jan 29 '14 at 17:50
  • 1
    Hi. I edited my answer to explain why I don't recommend changing /etc/paths. See the last paragraph. – monfresh Jan 29 '14 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .