我刚买了一台新的Mac,安装了OS X Lion系统,我在终端上检查了默认安装的git版本。我知道答案了

git --version
> git version 1.7.5.4

我想把git升级到最新的1.7.8.3版本,所以我下载了dmg安装程序“git-1.7.8.3-intel-universal-snow-leopard”。dmg”,然后我启动了它。

安装完成后,终端仍然显示版本为1.7.5.4。我做错了什么?


当前回答

如果你能补充以下内容可能会更好:

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

到主文件夹中名为.bashrc的文件。这样,您可能安装在/usr/local/git/bin中的任何其他软件也将首先被找到。

一个简单的方法就是输入:

echo "export PATH=/usr/local/git/bin:/usr/local/sbin:$PATH" >> ~/.bashrc

到终点站,它会为您办理的。

其他回答

为了保持两个版本,我只是改变了PATH环境变量的值,把新版本的git路径“/usr/local/git/bin/”放在开头,它强制使用最新版本:

$ echo $PATH 工作:/ bin: / usr / sbin: / sbin: / usr /地方/ bin: / opt / X11 / bin: / usr /地方/ git / bin / $ git——版本 git 2.4.9版本(Apple git -60)

原值:/usr/ bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin/

新值:/usr/local/ git/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

$ export PATH=/usr/local/git/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin $ git——版本 Git 2.13.0版本

在谷歌上搜索“在mac上升级git遇到麻烦”后,我阅读了几篇文章,并尝试了以下步骤,然后通过完成步骤4解决了问题:

I updated my terminal path by using the above mention export command. Every time I quit the terminal and restarted it, when I typed git --version the terminal, it still return the older version 1.8. I followed the README.txt instructions for upgrading to the current version 2.0.1 that comes with the .dmg installer and when I restarted the terminal, still no go. I looked for /etc/path/ folder as instructed above and the directory called "path" does not exist on my Mac. I am running OS X Mavericks version 10.9.4. Then I recalled I have Homebrew installed on my Mac and ran the following: brew --version brew update brew search git brew install git

这终于解决了我的问题。如果有人有一些见解,为什么这工作,进一步的见解将大大赞赏。我的系统上可能还有一些去年使用Ruby时遗留下来的路径设置。

对我来说,在Homebrew 1.6.7中,以下操作是有效的:

brew upgrade git

git主页上的安装程序默认安装到/usr/local/git中。但是,如果你安装XCode4,它会在/usr/bin中安装一个git版本。为了确保您可以轻松地从网站升级并使用最新的git版本,编辑您的配置文件信息,将/usr/local/git/bin放在$PATH中的/usr/bin之前,或者编辑/etc/paths并插入/usr/local/git/bin作为第一个条目。

它可能对某些人有帮助,至少改变/etc/paths中的顺序对我有用。

@rafaecheve的回答在我这个Mac用户身上非常有效。我在我的机器上安装了几个版本的git,但是使用了包管理器,Homebrew和以下代码:

brew link --overwrite git

我收到这个确认

Linking /usr/local/Cellar/git/2.32.0... 212 symlinks created.

拖鞋!