Posts Homebrew 替换国内源
Post
Cancel

Homebrew 替换国内源

Homebrew 默认 GitHub 源的拉取速度慢得令人发指,以至于知乎出现了一个令人鼻酸的回答:

poor-guy.jpg

为了对抗不公,所以必须使用国内镜像加速 Homebrew 的速度。中科大和清华两家的源做的很不错(此外还有 coding.net 的可选),下面介绍替换中科大的源。

更换 Git Repo 源

替换 brew:

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 pull origin master

更换 Homebrew Bottles 源

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

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

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

参考资料

OLDER POST NEWER POST

Comments powered by Disqus.

Search Results