天天看點

Mac 記錄之 Homebrew換源

問題

國内環境使用Homebrew安裝軟體很慢或者說卡死在Updating homebrew步驟,如下:

Updating Homebrew .. #速度很慢或者說卡死
           

方法

更新三個關鍵倉庫位址為Alibaba提供的位址

  • brew.git
  • homebrew-core.git
  • homebrew-bottles

brew.git 替換/還原

# 替換成阿裡巴巴的 brew.git 倉庫位址:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

#=======================================================

# 還原為官方提供的 brew.git 倉庫位址
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
           

homebrew-core.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-core.git 倉庫位址
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
           

homebrew-bottles 替換/還原

根據裝置macOS目前使用的shell版本決定使用哪種方式

echo $SHELL

# 如果你的輸出結果是 /bin/zsh,參考?的 zsh 終端操作方式
# 如果你的輸出結果是 /bin/bash,參考?的 bash 終端操作方式
           
  • zsh 終端操作
# 替換成阿裡巴巴的 homebrew-bottles 通路位址:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

#=======================================================

# 還原為官方提供的 homebrew-bottles 通路位址
vi ~/.zshrc
# 然後,删除 HOMEBREW_BOTTLE_DOMAIN 這一行配置
source ~/.zshrc
           
  • bash 終端操作
# 替換 homebrew-bottles 通路 URL:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

#=======================================================

# 還原為官方提供的 homebrew-bottles 通路位址
vi ~/.bash_profile
# 然後,删除 HOMEBREW_BOTTLE_DOMAIN 這一行配置
source ~/.bash_profile