前言
換了MacBook 16寸的電腦正好在使用brew安裝一些應用,發現一個小問題是每次執行如brew install ansible
命令停留在Updating Homebrew...
的時間特別長,在新加坡理論上應該和網絡無關,最後按照網絡上的方案選擇關閉每次檢查更新解決。
更新歷史
2020年10月13日 - 初稿
閱讀原文 - https://wsgzao.github.io/post/homebrew-update/
Homebrew關閉自動更新
通過環境變量關閉Homebrew自動更新解決Updating Homebrew方法最簡單
# 卡在Updating Homebrew好久
brew install ansible
Updating Homebrew...
# 關閉自動更新,在.zshrc文件中加入下方命令,如果是bash請加在.bash_profile文件中,全局變量可以sudo vi /etc/profile
vim ~/.zshrc
export HOMEBREW_NO_AUTO_UPDATE=true
# 刷新環境變量
source ~/.zshrc
Homebrew鏡像源加速
我們平時執行brew命令安裝軟件的時候,跟這三個倉庫有關:
- brew.git
- homebrew-core.git
- homebrew-bottles
使用阿里或者清華的Homebrew鏡像源代替可以進行加速
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
# 還原homebrew-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的話請寫在.bash_profile文件中。