HomeBrew 官方安裝太慢而失敗?這么搞就行.(轉(zhuǎn)載)

第一步,獲取install文件

把官網(wǎng)給的腳本拿下來
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

第二步,更改腳本中的資源鏈接,替換成清華大學(xué)的鏡像

就是把這兩句
BREW_REPO = “https://github.com/Homebrew/brew“.freeze
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze
更改為這兩句
BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git “.freeze
CORE_TAP_REPO = “https://mirrors.ustc.edu.cn/homebrew-core.git“.freeze
當(dāng)然如果這個鏡像有問題的話,可以換成別的

第三步,執(zhí)行腳本

/usr/bin/ruby brew_install

然后可以看到這幾句:

==> Tapping homebrew/core

Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

Error: Failure while executing: /usr/local/bin/brew tap homebrew/core

liyuanbadeMacBook-Pro:~ liyuanba$ git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

出現(xiàn)這個原因是因為源不通,代碼來不下來,解決方法就是更換國內(nèi)鏡像源:

執(zhí)行下面這句命令,更換為中科院的鏡像:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

就下載成功了

然后把homebrew-core的鏡像地址也設(shè)為中科院的國內(nèi)鏡像

cd "$(brew --repo)"

git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

執(zhí)行更新,成功:

brew update

最后用這個命令檢查無錯誤:

brew doctor

這樣海外和已經(jīng)有系統(tǒng)全局代理設(shè)置的朋友們就可以直接使用 brew 命令安裝軟件了。

接著換源:

直接使用 Homebrew 還需要更改默認源,不然誰用誰想打人,原因你懂的。以下是將默認源替換為國內(nèi) USTC 源的方法。

替換核心軟件倉庫

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

替換 cask 軟件倉庫(提供 macOS 應(yīng)用和大型二進制文件)

cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

替換 Bottles 源(Homebrew 預(yù)編譯二進制軟件包)

bash(默認 shell)用戶:

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

原文鏈接

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容