有沒有出現這種場景:使用brew install 安裝程序,一直卡在brew updating,這可能是使用着默認的github鏡像源導致,那么我們就需要將其切換到國內
1.鏡像切換(推薦中科大)
1)替換brew.git cd "$(brew --repo)" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git //清華 或 git remote set-url origin https://mirrors.ustc.edu.cn/brew.git //中科大 2)替換homebrew-core.git cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git //中科大 或 git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git //清華
3)替換homebrew-cask
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
4)替換homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
或
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile
5)應用生效 brew update -v (查看過程)
2.鏡像復原
# 重置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
3. 問題修復
# 診斷Homebrew的問題: $ brew doctor # 重置brew.git設置: $ cd "$(brew --repo)" $ git fetch $ git reset --hard origin/master # homebrew-core.git同理: $ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" $ git fetch $ git reset --hard origin/master # 應用生效: $ brew update