Homebrew 国内使用加速

可以选择的源:

  • 清华大学 mirrors.tuna.tsinghua.edu.cn
  • 中科大 mirrors.ustc.edu.cn

替换 Homebrew 默认源

1
2
3
4
5
6
7
8
9
# 替换 brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 替换 homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

brew update

替换 Home-brew Bottles 源

1
2
3
4
5
6
7
#对于bash用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

#对于zsh用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

测试下速度,果然飞起了

1
$ brew install wget

恢复默认设置的办法

1
2
3
4
5
6
7
8
9
# 重置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

brew update

2023-05-04 更新,最近在安装的时候经常遇到清华源有 404 的错误,更换为中科大源之后速度恢复正常

参考资料

  1. mac上安装brew如何加速
  2. Homebrew国内加速
  3. 镜像助手

cocowool

A FULL STACK DREAMER!