默认的官方源地址是境外的,必须翻墙,比较慢,可以切换为国内的数据源,速度比较快
Homebrew安装主要靠git仓库,切换源实际上就是切换相关git repo的remote url.
具体做法:
找到brew.git和homebrew-core.git的本地repo
切换两个repo的remote url
1、切换USTC源:https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git
(1)# 更换brew.git的源
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
(2)# 更换homebrew-core.git的源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
(3)brew update
注意,此时可能会报各种域名地址找不到,在/etc/hosts的文件中添加对应的IP即可
192.30.255.113 github.com
1113.250.94.254 api.github.com
12202.38.95.110 mirrors.ustc.edu.cn
(4)另外,还需要更换Homebrew Bottle源,这个只要在shell配置文件里加上(或更改)一个变量即可。
如zsh就是编辑~/.zshrc文件, bash就是~/.bash_profile文件:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
再 source ~/.bash_profile和 source ~/.zshrc 即可。
2、切换清华源:https://mirror.tuna.tsinghua.edu.cn/help/homebrew/
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.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
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-science"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-science.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-python"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-python.git
brew update
3、重置官方源
# 重置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