Mac系统使用Homebrew升级Git版本

来源:互联网 发布:淘宝二次元粉丝节 编辑:程序博客网 时间:2024/06/05 07:05

原先版本  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 --versiongit 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 doctorPlease note that these warnings are just used to help the Homebrew maintainerswith debugging if you file an issue. If everything you use Homebrew for isworking fine: please don't worry and just ignore them. Thanks!Warning: You have unlinked kegs in your CellarLeaving kegs unlinked can lead to build-trouble and cause brews that depend onthose kegs to fail to run properly once built. Run `brew link` on these:  gitWarning: /usr/bin occurs before /usr/local/binThis means that system-provided programs will be used instead of thoseprovided by Homebrew. The following tools exist at both paths:  git  git-cvsserver  git-shell  git-upload-packConsider setting your PATH so that /usr/local/binoccurs before /usr/bin. Here is a one-liner:  echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profileWarning: 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 --versiongit version 2.10.0



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

DavidtekiMacBook-Air:~ du$ brew upgrade git