您的位置:首页 > 其它

Mac系统使用Homebrew升级Git版本

2017-08-16 13:30 627 查看
原先版本  1.7.10.2

升级后版本 2.10.0

① 打开终端,输入brew install git:

DavidtekiMacBook-Air:~ du$ brew install git
② git安装完成后,输入git --version, 发现仍旧是1.7.10.2
DavidtekiMacBook-Air:~ du$ git --version
git version 1.7.10.2 (Apple Git-33)

③ 输入which git,发现git位于/usr/bin/git目录下

DavidtekiMacBook-Air:~ du$ which git
/usr/bin/git
④ 使用brew doctor,重点看第二个warning。
原因是:brew install git后的git安装包在 /usr/local/git 目录下,而系统默认/usr/bin 在/usr/local/bin之前。

所以解决方法就是将/usr/local/bin放在/usr/bin之前。

DavidtekiMacBook-Air:~ du$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
git

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:
git
git-cvsserver
git-shell
git-upload-pack

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

Warning: Your Xcode (4.5.2) is outdated.
Please update to Xcode 8.2.1 (or delete it).
Xcode can be updated from the App Store.
⑤ 使用 pico .bash_profile命令,打开配置文件,输入export PATH="/usr/local/bin:$PATH",
然后CONTRL+X退出,Y保存,回车

DavidtekiMacBook-Air:~ du$ pico .bash_profile
export PATH="/usr/local/bin:$PATH"
⑥ 退出终端,重新打开,并输入git --version,版本号变为2.10.0

DavidtekiMacBook-Air:~ du$ git --version
git version 2.10.0


PS:以后如果要直接更新git,在终端直接输入brew upgrade git即可(brew upgrade为升级所有的包)

DavidtekiMacBook-Air:~ du$ brew upgrade git
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: