Mac Homebrew 更换中国源 - 简书

Homebrew安装主要靠git仓库,切换源实际上就是切换相关git repo的remote url.

具体做法:

  • 找到brew.githomebrew-core.git的本地repo
  • 切换两个repo的remote url

切换USTC源:https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git

# 更换brew.git的源
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 更换homebrew-core.git的源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

brew update

另外,还需要更换Homebrew Bottle源,这个只要在shell配置文件里加上(或更改)一个变量即可。
如zsh就是编辑~/.zshrc文件, bash就是~/.bash_profile文件:

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

切换清华源: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

重置官方源:

# 重置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

原网址: 访问
创建于: 2020-05-15 01:18:26
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论