Post

Homebrew 替换国内源

Homebrew 默认 GitHub 源的拉取速度慢得令人发指,必须使用国内镜像加速 Homebrew 的速度。中科大和清华两家的源做的很不错(此外还有 coding.net 的可选),下面介绍替换中科大的源。

更换源代码仓库

替换主仓库:

1
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git && git pull origin master

替换 homebrew-core 仓库:

1
$ git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-core" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git && git pull origin master

替换 homebrew-cask 仓库:

1
$ git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git && git pull origin master

更换 Homebrew Bottles 源:

1
2
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

完毕后,执行更新与升级:

1
$ brew update && brew upgrade

恢复官方配置

某些情况下,譬如肉身翻墙了,可能需要换回官方的 GitHub 源:

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

另外,在 ~/.bash_profile 中去除环境变量 HOMEBREW_BOTTLE_DOMAIN,也就是 更换 Homebrew Bottles 源 的逆向操作:

1
$ sed -i "/HOMEBREW_BOTTLE_DOMAIN/d" ~/.bash_profile && source ~/.bash_profile

参考资料

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.