How to update my version of git on OSX 10.8

I'm on OSX 10.8.2 and I'm running git git v1.7.4.4

I just installed git on a remote server and it's version 1.11.x. I'm I would like to be running the same version of the software but I cannot figure out how to update git on my laptop.

I attempted to follow the steps listed here, which instruct to download the git-OSX-installer, run the install (which ran smoothly) and then do:

$ sudo mkdir -p /usr/local/bin
$ sudo ln -s /usr/local/git/bin/git /usr/local/bin/git

But after this I do git --version and it's still 1.7.4.4. Did I just reinstall the same version? Or did I install a newer version somewhere else?

I've been reading similar questions and I think the issue is that OSX ships with an old version of git installed in a different location then where the git-osx-installer or mac ports will put it. But I'm not sure how to correct this. Thanks in advance for your advice.

Update:

which git returns: /usr/bin/git

echo $PATH returns: /opt/local/bin:/opt/local/sbin:/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin

Update2:

ESL ~/Downloads$ export PATH=/usr/local/bin:$PATH
ESL ~/Downloads$ which git
/usr/local/bin/git
ESL ~/Downloads$ 
ESL ~/Downloads$ git --version
git version 1.8.1.3

It appears I installed the newer git version in local. So should I add the export PATH=/usr/local/bin:$PATH to my .bash_profile? Is it a problem that both versions of git are installed?

I added export PATH=/usr/local/bin:$PATH to the bottom of my ~/.bash_profile and now the new version of git runs.


Since /usr/bin shows up before /usr/local/bin in your path, the git executable in /usr/bin will be given precedence. try this in your shell:

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

On a side note, I'd strongly recommend using homebrew for managing installations such as this on macos


The best way to update any binary on a Mac OSX machine is to use the package(s) developed specifically for Mac (a .dmg or .pkg download).

In the case of git this is at: http://git-scm.com/download/mac (clicking on this link should automatically start the download of the latest version of git for Mac).

However, in this case (at least for my 10.8.3 MacBook) this was not quite the whole story: the package installs git in /usr/local/git and then adds that path at the end of $PATH - which defeats the whole purpose IMO.

I have manually modified my .bashrc so as to have something similar to what suggested above:

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

Once you do that, you should see the correct version of git being picked:

$ git --version
git version 1.8.2.2 

Note that this won't work for any app that is launched interactively (eg, via the docking bar) - you'll have to run the additional script provided in the downloaded package; see the README for instructions.


I had a similar issue in Cygwin (linux environment compiled for windows). I would do

which git

and it would respond with the correct location of the updated git compiled from source, but wouldn't actually use it until I did

hash -r git

I don't claim to understand what this did or why it had to be done, but after that git --version replied with '1.8.2.rc0.22.gb3600c3' which was clearly no longer the old git shipped with Cygwin. This may not apply to OSX, but give it a shot if which git is locating the updated binary.

链接地址: http://www.djcxy.com/p/63348.html

上一篇: “bash:command not found”错误

下一篇: 如何在OSX 10.8上更新我的git版本