1、升级brew版本(如果出现以下提示,说明全都更新好了)
ruby-2.6.3 ~ ❯ brew update
Already up-to-date.
2、查看当前git指向和版本
ruby-2.6.3 ~ ❯ which git
/usr/bin/git
ruby-2.6.3 ~ ❯ git version
git version 2.17.2 (Apple Git-113)
3、直接安装git
brew install git
可能会出现以下错误提示:
Error: The following directories are not writable by your user:
/usr/local/lib
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/lib
And make sure that your user has write permission.
chmod u+w /usr/local/lib
ruby-2.6.3 ~ ❯ sudo brew install git
Password:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
解决方法:
sudo chown -R $(whoami) /usr/local
4、安装git最新版本
ruby-2.6.3 ~ ❯ brew install git
==> Downloading https://homebrew.bintray.com/bottles/git-2.26.2_1.mojave.bottle.tar.gz
==> Installing git
==> Pouring git-2.26.2_1.mojave.bottle.tar.gz
==> Caveats
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completions and functions have been installed to:
/usr/local/share/zsh/site-functions
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/git
==> Summary
🍺 /usr/local/Cellar/git/2.26.2_1: 1,471 files, 46.0MB
5、尝试解绑指向并重新设置
ruby-2.6.3 ~ ❯ brew unlink git
Unlinking /usr/local/Cellar/git/2.26.2_1... 206 symlinks removed
ruby-2.6.3 ~ ❯ brew link git
Linking /usr/local/Cellar/git/2.26.2_1... 206 symlinks created
6、关闭终端,重新打开后查看git指向和版本
ruby-2.6.3 ~ ❯ which git
/usr/local/bin/git
ruby-2.6.3
wangpingyang@wangpingyangs-MacBook-Pro:~
ruby-2.6.3 ~ ❯git version
git version 2.26.2
ruby-2.6.3
网友评论