簡 述: 在重裝 Mac
系統的 💻 上,安裝 HomeBrew
,執行官方命令失敗,報錯 curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
的 解決方法: 修改 hosts 文件 [使用raw.githubusercontent.com
的真實IP] 。
Google
了下,網上那轉載了一篇文章已經有幾十遍了,或許也對你不起效吧,即使想找一篇不一樣的也這麼的困難,還是我自己動手;如果對你有效,就把這篇頂上去,爲其他人節約時間,提供一個新的方法的
問題背景:
在我的 MacOS 10.14.6
上面,執行命令 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
之後,顯示連接 github 失敗。
# 報錯原因
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
報錯原因:
由於某種原因,導致github
的raw.githubusercontent.com
域名解析被污染了,所以,需要通過修改hosts
解決這個問題;
解決方案[修改 hosts 文件]:
前提條件: 安裝了 xcode
或者 Command Line Tools for Xcode
若是不需要使用 xcode 開發,只用安裝後者即可,命令如下:
xcode-select --install //安裝 Command Line Tools for Xcode
-
查閱真實的
IP
地址:在
https://www.ipaddress.com/
查詢raw.githubusercontent.com
的真實IP。 -
修改
hosts
sudo vim /etc/hosts
在文件最後一行加上,然後保存
199.232.68.133 raw.githubusercontent.com
-
再次輸入Homebrew 官網 命令
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
-
等待即可安裝成功
換國內鏡像源:
安裝完成之後,當然是要進行替換 Homebrew
和 Homebrew Bottles
換源,否則就是浪費時間。
下面的國內鏡像源任選其一:
- 使用中科大的源:替換及重置Homebrew默認源 (具體操作如下)
- 使用清華的源:Homebrew/Linuxbrew 鏡像使用幫助
替換及重置Homebrew默認源
#替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
#替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
Homebrew Bottles源
Homebrew Bottles 是 Homebrew 提供的二進制代碼包,目前鏡像站收錄了以下倉庫:
- homebrew/homebrew-core
- homebrew/homebrew-dupes
- homebrew/homebrew-games
- homebrew/homebrew-gui
- homebrew/homebrew-python
- homebrew/homebrew-php
- homebrew/homebrew-science
- homebrew/homebrew-versions
- homebrew/homebrew-x11
# 對於bash用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
# 對於zsh用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
參考博客:
homebrew.rb 文件