前言
換了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):
- brew.git
- homebrew-core.git
- 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文件中。