4

I have installed GIT 1.7.7.1 via homebrew and had to do a

sudo brew link git

to link git to

/usr/local/bin

When I run git --version in terminal I get an older version of Git (1.7.5.6)

Is it possible to link to the new version instead?

Yannick Schall
  • 32,601
  • 6
  • 29
  • 42
  • Related: http://stackoverflow.com/questions/5364614/is-there-a-problem-with-having-usr-local-bin-before-usr-bin-on-the-path-in-os – Matt Montag Oct 31 '12 at 18:10

2 Answers2

3

Looks like /usr/bin go before /usr/local/bin in $PATH and hence take precedence. I suggest to change order of paths in $PATH.

(Also you may try to define alias: alias git=/usr/local/bin/git)

Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
  • this is my path, export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH" – Yannick Schall Oct 30 '11 at 21:04
  • /usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/Users/yannick/.rvm/gems/ruby-1.9.2-p290/bin:/Users/yannick/.rvm/gems/ruby-1.9.2-p290@global/bin:/Users/yannick/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/yannick/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin – Yannick Schall Oct 30 '11 at 23:30
  • and this is my path, but I sill get the older git version – Yannick Schall Oct 30 '11 at 23:30
  • Actually it works when I reload the ~/.profile. But when I restart terminal I have to reload the path manually again. Is ~/.profile not the right place where to put $PATH? – Yannick Schall Oct 30 '11 at 23:34
  • @yannick-schall What shell do you use? If it's a `bash` then I suggest to set `$PATH` in `~/.bashrc`. For Zsh put it in `~/.zshrc` – Slava Semushin Oct 31 '11 at 04:22
  • I use Bash, I've added everything to my ~/.bash_profile and it works. Is there a big difference between the two? Cheers – Yannick Schall Oct 31 '11 at 21:05
2

Here is another solution that worked for me.

I found this related post to be very helpful. Instead of changing the $PATH variable, it just has you simply edit your /etc/paths file. https://superuser.com/questions/324616/how-should-i-set-the-path-variable-on-my-mac-so-the-hombrew-installed-tools-are/533708#533708

  1. Open Terminal on your Mac
  2. Type the command: sudo nano /etc/paths
  3. Enter your password if you're asked for it
  4. You will see a list of paths. Edit the list them so that /usr/local/bin path is entered above the /usr/bin path
  5. Save step 1 - Control + X
  6. Save step 2 - Y
  7. Restart Terminal

Here's what mine looks like after I did that:

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

Credit to @jrwren & @jthomas over at StackOverflow for their answers.

Community
  • 1
  • 1
zechdc
  • 3,374
  • 9
  • 40
  • 52
  • Upvoted it is helpful for me. Future reader can follow [Upgrading to Git 2.0](http://rayhightower.com/blog/2014/05/30/upgrading-to-git-2-dot-0/) link as well. – Arup Rakshit Jan 05 '15 at 06:15