Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 244
emersonthis Avatar asked Feb 24 '13 22:02

emersonthis


2 Answers

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.

like image 176
Marco Massenzio Avatar answered Dec 29 '22 22:12

Marco Massenzio


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

like image 36
Ali-Akber Saifee Avatar answered Dec 29 '22 22:12

Ali-Akber Saifee