1. 程式人生 > >Mac系統使用Homebrew升級Git版本

Mac系統使用Homebrew升級Git版本

原先版本  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