brew 替换源与还原

查看本地使用的镜像源

cd "$(brew --repo)" && git remote -v

若如下结果表示使用的是官方源

origin	https://github.com/Homebrew/brew (fetch)
origin	https://github.com/Homebrew/brew (push)

切换镜像源有三个库要切换

3 个仓库地址:

  • brew.git
  • homebrew-core.git
  • homebrew-bottles

切换 Homebrew 镜像源为阿里镜像源

  1. 更换brew.git
cd "$(brew --repo)" && git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
  1. 更换 homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
  1. 更换homebrew-cask.git(M1的配置和之前的不一样,没有 cask 这个目录,忽略)
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
  1. 更换homebrew-bottles,在对应shell配置执行
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc &&
source ~/.zshrc
  • 本人使用的zshrc,若是使用bash,操作文件变更成bash_profile
  1. **brew update ** 刷新配置
brew update

切换 Homebrew 镜像源为官方

  1. 更换brew.git
cd "$(brew --repo)" && git remote set-url origin https://github.com/Homebrew/brew.git
  1. 更换 homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://github.com/Homebrew/brew.git
  1. 更换homebrew-cask.git(M1的配置和之前的不一样,没有 cask 这个目录,忽略)
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
  1. 更换homebrew-bottles,在对应shell中注释掉刚刚的配置
vim ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles
source ~/.zshrc
  • 本人使用的额ezshrc,若是使用bash,操作文件变更成bash_profile
  1. **brew update ** 刷新配置
brew update

你可能感兴趣的:(brew,brew切换源,git,github)