今天在 Mac 裝 Homebrew 遇到了一個問題,在網上找了大量解決方案,做個總結。
Mac 版本 High Sierra 10.13.6。
問題描述
在 Mac 終端輸入了 Homebrew 官網給的安裝指令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
結果安裝到最后出現了錯誤:
fatal: unable to access 'https://github.com/Homebrew/brew/': Could not resolve host: github.com
Failed during: git fetch origin master:refs/remotes/origin/master --tags --force
網上都說是網不通,可是我也掛着 ss,應該不是這個問題,很多解決方法是修改成鏡像的鏈接,不過貌似都不見效。試着在終端 ping 了一下 GitHub 的地址:
ping github.com
結果出現了下面這個結果,還真是網不通。
ING github.com (13.250.177.223): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
解決方案
修改 host 配置,在終端中輸入下列指令,打開編輯文件。
sudo vi /etc/hosts
按 s鍵 進入編輯模式,在最下面添加 192.30.253.113 github.com
按 control + c鍵 保存,接着輸入:wq
退出即可。
再次嘗試在終端 ping github.com,發現已經成功了。
接着繼續在終端輸入官網的安裝指令,就能安裝成功了。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
常見問題
如果在安裝過程中出現以下情況,就是網不通,再次輸入官網安裝指令即可。
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: The remote end hung up unexpectedly