Homebrew換源

HomeBrew 官方安裝太慢而失敗?更換homebrew源

第一步,獲取install文件

把官網(wǎng)給的腳本拿下來

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

第二步,更改腳本中的資源鏈接,替換成國內(nèi)的鏡像

如下:

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

如果這個鏡像有問題的話,可以換成別的

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

使用ruby安裝homebrews

/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/'](https://github.com/Homebrew/homebrew-core/' rel=): 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

換源

這里針對mac上已經(jīng)安裝了homebrew的用戶,在此基礎(chǔ)上跟換brew的源鏡像

直接使用 Homebrew 還需要更改默認(rèn)源,不然誰用誰想打人,原因你懂的。以下是將默認(rèn)源替換為國內(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)用和大型二進(jìn)制文件)

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

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

bash(默認(rèn) shell)用戶:

echo 'export HOMEBREW_BOTTLE_DOMAIN=[https://mirrors.ustc.edu.cn/homebrew-bottles'](https://mirrors.ustc.edu.cn/homebrew-bottles' rel=) >> ~/.bash_profile 
source ~/.bash_profile

zsh 用戶:

echo 'export HOMEBREW_BOTTLE_DOMAIN=[https://mirrors.ustc.edu.cn/homebrew-bottles'](https://mirrors.ustc.edu.cn/homebrew-bottles' rel=) >> ~/.zshrc 
source ~/.zshrc

參考

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容