mac 安装or升级Git
Homebrew macOS
Homebrew macOS(或 Linux)缺失的软件包的管理器 brew.sh/index_zh-cn
Homebrew 是一个软件包管理器。它的作用就是将软件包安装到自己的目录中,然后将其文件符号链接到 /usr/local
brew list
brew info git
1. mac系统xcode含git
mac会默认安装xcode自带的git
2. install git
brew install git
==> Installing dependencies for git: gettext and pcre2
==> Installing git dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.20.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/fa/fa2096f80238b8f4d9f3724d526626ab4db5c0586f3746ee13fc66e5a625aa1a?__gda__=exp=1569381062~hmac=c97e42a3c09abe96b2618b9bacc0241dc4010e5f
######################################################################## 100.0%
==> Pouring gettext-0.20.1.mojave.bottle.tar.gz
==> Caveats
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.
If you need to have gettext first in your PATH run:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile
For compilers to find gettext you may need to set:
export LDFLAGS="-L/usr/local/opt/gettext/lib"
export CPPFLAGS="-I/usr/local/opt/gettext/include"
==> Summary
🍺 /usr/local/Cellar/gettext/0.20.1: 1,899 files, 18.5MB
==> Installing git dependency: pcre2
==> Downloading https://homebrew.bintray.com/bottles/pcre2-10.33.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/fb/fb30c3eebba4483a10378bc8df52f96761fed4a1ac5572ad1bf4afbf2f8638c5?__gda__=exp=1569381077~hmac=50519d19a5c126346692b191fed2c0e8b59735a3
######################################################################## 100.0%
==> Pouring pcre2-10.33.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/pcre2/10.33: 226 files, 5.7MB
==> Installing git
==> Downloading https://homebrew.bintray.com/bottles/git-2.23.0_1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/84/846c80d096bd49662e34de8144e73b2df017a3acb35a15942429e111951ba343?__gda__=exp=1569381086~hmac=c623daa34fccf94571ada2b614b55954a5a2e327
######################################################################## 100.0%
==> Pouring git-2.23.0_1.mojave.bottle.tar.gz
==> Caveats
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.23.0_1: 1,543 files, 44.9MB
==> Caveats
==> gettext
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.
If you need to have gettext first in your PATH run:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile
For compilers to find gettext you may need to set:
export LDFLAGS="-L/usr/local/opt/gettext/lib"
export CPPFLAGS="-I/usr/local/opt/gettext/include"
==> git
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
3. 确认git版本
如果是指向xcode自带的git,就改变默认 Git 指向
Honglei:~ honglei$ which git
/usr/bin/git
Honglei:~ honglei$ git --version
git version 2.20.1 (Apple Git-117)
4. brew link 指向git
接下来我们通过 brew link 将 git 指向我们通过 Homebrew 安装的 git
Honglei:~ honglei$ brew link git --overwrite
Warning: Already linked: /usr/local/Cellar/git/2.23.0_1
To relink: brew unlink git && brew link git
5. 验证link方法
link 成功后,退出终端后,再次打开。然后查看 git 指向和版本信息。
Honglei:~ honglei$ which git
/usr/local/bin/git
git --version
git version 2.20.1 (Apple Git-117)
6. 配置path
最后实现不行,直接把git的路径配置到path中。
PATH="${MAVEN_HOME}/bin:${JAVA_HOME}:${PATH}:/usr/local/bin/git"
更新 git
查看
~ brew info git
git: stable 2.29.2, HEAD
Distributed revision control system
https://git-scm.com
...
更新
brew upgrade git
更新过程如下
brew upgrade git
Updating Homebrew...
Warning: You are using macOS 11.1.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
pre-release version.
==> Upgrading 1 outdated package:
git 2.23.0_1 -> 2.29.2
==> Upgrading git 2.23.0_1 -> 2.29.2
==> Downloading https://ftp.gnu.org/gnu/gettext/gettext-0.21.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/fbd8967fd8256b2e1856b74e8ff0f3d8371cb652c5768e47649613a69d4dc841--gettext-0.21.tar.xz
==> Downloading https://ftp.pcre.org/pub/pcre/pcre2-10.35.tar.bz2
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/48997c77a7dae2fb85d52234e92e9032019609e091e23d72529d1e552978a260--pcre2-10.35.tar.bz2
==> Downloading https://mirrors.edge.kernel.org/pub/software/scm/git/git-htmldocs-2.29.2.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/121a858acf277913dc50e88327bdab2d23472eaef1be3d6d578e0d2af1581398--git-htmldocs-2.29.2.tar.xz
==> Downloading https://mirrors.edge.kernel.org/pub/software/scm/git/git-manpages-2.29.2.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/943040db2aac5a66a4faae1cb07ea9ea9a98ee2c2928750d2f86277a1b64099b--git-manpages-2.29.2.tar.xz
==> Downloading https://cpan.metacpan.org/authors/id/R/RJ/RJBS/Net-SMTP-SSL-1.04.tar.gz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/0726c68dac390b617cefcc880f076b50795463c1fba286d46a53082ebed2bc9d--Net-SMTP-SSL-1.04.tar.gz
==> Downloading https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.29.2.tar.xz
Already downloaded: /Users/honglei/Library/Caches/Homebrew/downloads/6b8b369d6a5b8c38330cef909d4a876403d2badc5ab22b2118a562520da30d7c--git-2.29.2.tar.xz
==> Installing dependencies for git: gettext and pcre2
==> Installing git dependency: gettext
==> ./configure --prefix=/usr/local/Cellar/gettext/0.21 --with-included-gettext gl_cv_func_ftello_works=yes --with-included-glib --with-included-libcroco --with-included-libunistring --with-emacs --wi
==> make
==> make install
🍺 /usr/local/Cellar/gettext/0.21: 1,953 files, 19.8MB, built in 9 minutes 52 seconds
==> Installing git dependency: pcre2
==> ./configure --prefix=/usr/local/Cellar/pcre2/10.35 --enable-pcre2-16 --enable-pcre2-32 --enable-pcre2grep-libz --enable-pcre2grep-libbz2 --enable-jit
==> make
==> make install
🍺 /usr/local/Cellar/pcre2/10.35: 230 files, 6.1MB, built in 53 seconds
==> Installing git
==> make install prefix=/usr/local/Cellar/git/2.29.2 sysconfdir=/usr/local/etc CC=clang CFLAGS= LDFLAGS= NO_TCLTK=1 NO_OPENSSL=1 APPLE_COMMON_CRYPTO=1
==> make CC=clang CFLAGS= LDFLAGS=
==> make clean
==> make
==> make test
==> make CC=clang CFLAGS= LDFLAGS=
==> 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.29.2: 1,479 files, 39.7MB, built in 1 minute 10 seconds
Removing: /usr/local/Cellar/git/2.23.0_1... (1,543 files, 44.9MB)
==> Upgrading 2 dependents:
libidn2 2.2.0_1 -> 2.3.0, wget 1.20.3_1 -> 1.20.3_2
==> Upgrading libidn2 2.2.0_1 -> 2.3.0
==> Downloading https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
######################################################################## 100.0%
==> Downloading https://ftp.gnu.org/gnu/libidn/libidn2-2.3.0.tar.gz
######################################################################## 100.0%
==> Installing dependencies for libidn2: pkg-config
==> Installing libidn2 dependency: pkg-config
==> ./configure --prefix=/usr/local/Cellar/pkg-config/0.29.2_3 --disable-host-tool --with-internal-glib --with-pc-path=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/local
==> make
==> make install
🍺 /usr/local/Cellar/pkg-config/0.29.2_3: 11 files, 656.6KB, built in 1 minute 37 seconds
==> Installing libidn2
==> ./configure --prefix=/usr/local/Cellar/libidn2/2.3.0 --with-libintl-prefix=/usr/local/opt/gettext --with-packager=Homebrew
==> make install
🍺 /usr/local/Cellar/libidn2/2.3.0: 72 files, 808.2KB, built in 56 seconds
Removing: /usr/local/Cellar/libidn2/2.2.0_1... (70 files, 700.9KB)
==> Upgrading wget 1.20.3_1 -> 1.20.3_2
==> Downloading https://www.openssl.org/source/openssl-1.1.1h.tar.gz
######################################################################## 100.0%
==> Downloading https://ftp.gnu.org/gnu/wget/wget-1.20.3.tar.gz
######################################################################## 100.0%
==> Installing dependencies for wget: openssl@1.1
==> Installing wget dependency: openssl@1.1
==> perl ./Configure --prefix=/usr/local/Cellar/openssl@1.1/1.1.1h --openssldir=/usr/local/etc/openssl@1.1 no-ssl3 no-ssl3-method no-zlib darwin64-x86_64-cc enable-ec_nistp_64_gcc_128
==> make
==> make test
==> make install MANDIR=/usr/local/Cellar/openssl@1.1/1.1.1h/share/man MANSUFFIX=ssl
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs
and run
/usr/local/opt/openssl@1.1/bin/c_rehash
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/openssl@1.1/1.1.1h: 8,060 files, 18.4MB, built in 8 minutes 50 seconds
==> Installing wget
==> ./configure --prefix=/usr/local/Cellar/wget/1.20.3_2 --sysconfdir=/usr/local/etc --with-ssl=openssl --with-libssl-prefix=/usr/local/opt/openssl@1.1 gl_cv_func_ftello_works=yes --disable-pcre --dis
==> make install
🍺 /usr/local/Cellar/wget/1.20.3_2: 49 files, 4.0MB, built in 2 minutes 17 seconds
Removing: /usr/local/Cellar/wget/1.20.3_1... (50 files, 4.0MB)
==> Checking for dependents of upgraded formulae...
==> No broken dependents found!
==> Caveats
==> git
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
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs
and run
/usr/local/opt/openssl@1.1/bin/c_rehash
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
➜ git version
git version 2.29.2