mac默认的homebrew源托管与github,其在国内不好访问。所以很多同学发现update brew时候常常失败。
解决方法就是替换brew的源。实际操作中,有4个源需要替换。(这里用的是中科大的源,其他也有不错的,比如清华的,大家可以自行搜索)
1、替换homebrew默认源。
默认是https://github.com/Homebrew/brew.git,替换:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
2、替换homebrew-core默认源
默认是https://github.com/Homebrew/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、替换homebrew-cask默认源
默认是https://github.com/Homebrew/homebrew-cask,替换
cd /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-cask.git
4、替换homebrew bottles
实际就是修改环境变量。我的mac默认是没有这个变量的,目前我也没用到homebrew bottle,不过看其他资料有声明这个变量的,方法是
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
如果想恢复官方源,只需要把以上4步反向操作。当然在替换时候也可以使用git remote set-url --add origin <addr>这样会另添加一个源,原来的源也会保留,具体我们可以通过git config -e看配置文件.