替换国内镜像源让 Homebrew 起飞

推荐直接使用一键切换脚本:一键切换brew国内镜像源

1. 基本镜像 formula

1.1. 替换

1
2
3
4
5
6
7
# 参见官网:https://mirror.tuna.tsinghua.edu.cn/help/homebrew
➜ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
➜ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
➜ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

# 更新
➜ brew update

1.2. 还原

1
2
3
4
5
➜  git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
➜ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
➜ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

➜ brew update

2. 二进制预编译包 bottles

1
2
3
4
# 参见官网:https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles
# 如果你使用的不是 zsh,则替换 .zshrc 为 .bash_profile 或对应的文件
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc