【Mac】安裝 Homebrew 出錯 Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

今天在 Mac 裝 Homebrew 遇到了一個問題,在網上找了大量解決方案,作個總結。git

Mac 版本 High Sierra 10.13.6。github

問題描述

在 Mac 終端輸入了 Homebrew 官網給的安裝指令:ruby

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

結果安裝到最後出現了錯誤:curl

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 的地址:fetch

ping github.com

結果出現了下面這個結果,還真是網不通。url

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 配置,在終端中輸入下列指令,打開編輯文件。code

sudo vi /etc/hosts

s鍵 進入編輯模式,在最下面添加 192.30.253.113 github.comblog

control + c鍵 保存,接着輸入:wq退出便可。rem

再次嘗試在終端 ping github.com,發現已經成功了。it

接着繼續在終端輸入官網的安裝指令,就能安裝成功了。

/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
相關文章
相關標籤/搜索