Updating Homebrew 卡住的解決方案

前言

換了MacBook 16寸的電腦正好在使用brew安裝一些應(yīng)用,發(fā)現(xiàn)一個(gè)小問題是每次執(zhí)行如brew install ansible命令停留在Updating Homebrew...的時(shí)間特別長(zhǎng),在新加坡理論上應(yīng)該和網(wǎng)絡(luò)無關(guān),最后按照網(wǎng)絡(luò)上的方案選擇關(guān)閉每次檢查更新解決。

更新歷史

2020年10月13日 - 初稿

閱讀原文 - https://wsgzao.github.io/post/homebrew-update/


Homebrew關(guān)閉自動(dòng)更新

通過環(huán)境變量關(guān)閉Homebrew自動(dòng)更新解決Updating Homebrew方法最簡(jiǎn)單

# 卡在Updating Homebrew好久
brew install ansible
Updating Homebrew...

# 關(guān)閉自動(dòng)更新,在.zshrc文件中加入下方命令,如果是bash請(qǐng)加在.bash_profile文件中,全局變量可以sudo vi /etc/profile
vim ~/.zshrc
export HOMEBREW_NO_AUTO_UPDATE=true

# 刷新環(huán)境變量
source ~/.zshrc

Homebrew鏡像源加速

我們平時(shí)執(zhí)行brew命令安裝軟件的時(shí)候,跟這三個(gè)倉(cāng)庫(kù)有關(guān):

  1. brew.git
  2. homebrew-core.git
  3. homebrew-bottles

使用阿里或者清華的Homebrew鏡像源代替可以進(jìn)行加速

https://mirrors.aliyun.com/homebrew/

https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

# 替換brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

# 替換homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

# 替換homebrew-bottles訪問地址
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

# 還原brew.git
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

# 還原h(huán)omebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

# 還原的話就是刪除HOMEBREW_BOTTLE_DOMAIN,上面的是zsh的命令,如果是bash的話請(qǐng)寫在.bash_profile文件中。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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