刚开始默认安装,使用的是GitHub的源,用过的应该就知道更新下载安装的时候会非常慢。
下面教程是自己换源的操作,也是参考了其他人的做法,同时去清华大学开源软件镜像站上找了下。一般替换国内源有两个,一个是中科大,一个就是清华了。
中科大:https://mirrors.ustc.edu.cn
清华:https://mirrors.tuna.tsinghua.edu.cn
下面以清华的源为例操作一下。
# 清华大学源:
# 替换brew.git:
$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换homebrew-core.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
# 替换homebrew-cask.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# 替换homebrew-bottles:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 如果是用zsh的,需要把homebrew-bottles的配置信息配置在 ~/.zshrc里面
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
# 更换后测试工作是否正常:
$ brew update
如果需要替换回默认源,可以按照如下命令操作:
# 需要还原的话,把上面替换的清华的源替换回默认源即可
# GitHub源:
# 替换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
# 替换homebrew-cask.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
$ git remote set-url origin https://github.com/Homebrew/homebrew-cask.git
# 更换后测试工作是否正常:
$ brew update