MacOS10.15安裝Git
一、所需網站
Git官網:https://git-scm.com
Homebrew官網:https://brew.sh
二、先安裝Homebrew
1、第一種方法:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)
在terminal中輸入該命令進行安裝
報錯:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
在terminal中執行curl命令curl https://raw.githubusercontent.com/Homebrew/install/master/install.sh
依然是這個問題,嘗試ping這個網址,ping raw.githubusercontent.com
猜測是DNS的問題導致,嘗試修改hosts
查詢網站的ip地址,使用https://www.ipaddress.com查詢raw.githubusercontent.com
的ip地址為199.232.68.133
修改MacOS的hosts文件sudo vi /etc/hosts
,增加199.232.68.133 raw.githubusercontent.com
再次嘗試ping的時候就可以ping通了
再次執行 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
安裝即可。
2、第二種方法:
由於國內直接使用Homebrew官網的方式安裝比較慢,很容易失敗,所以可以用另一種方法。
1、先將官網的install.sh保存到本地文件
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh >>brew_install.sh
2、執行該腳本,可能會卡在tapping homebrew/core
/bin/bash brew_install.sh
3、手動更換中科院的鏡像來下載
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
4、再次執行
/bin/bash brew_install.sh
5、安裝成功
三、安裝Git
實際上安裝好Homebrew之后,git也已經安裝好了
輸入brew install git
安裝完成