跳到主要内容

macOS brew换源

使用brew 命令安装软件的时候,与 3 个仓库地址有关,换源主要是修改这三个仓库的远程仓库地址

  1. brew.git
  2. homebrew-core.git
  3. homebrew-bottles

替换brew.git 仓库地址

# 中国科大: https://mirrors.ustc.edu.cn/brew.git
# 清华大学: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

恢复默认:

cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

替换homebrew-core.git 仓库地址

# 中国科大: https://mirrors.ustc.edu.cn/homebrew-core.git
# 清华大学: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

恢复默认:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

替换homebrew-bottles 访问地址

这个步骤跟你的 macOS 系统使用的 shell 版本有关系,先来查看当前使用的 shell 版本

echo $SHELL
/bin/zsh

zsh替换成阿里巴巴的 homebrew-bottles 访问地址

# 中国科大: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
# 清华大学: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

恢复默认:

vi ~/.zshrc
# 然后,删除 HOMEBREW_BOTTLE_DOMAIN 这一行配置
source ~/.zshrc

查看brew config

brew config

这是是默认的

$ brew config
HOMEBREW_VERSION: 4.0.21
ORIGIN: https://github.com/Homebrew/brew.git
HEAD: 9d0b7361d1a197949dbb47b761405075f83983b7
Last commit: 4 days ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 63589f1a8e3cd0b1d5ee7eb25275cedb731ef73d
Core tap last commit: 4 months ago
Core tap branch: master
Core tap JSON: 10 Jun 10:00 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_GITHUB_API_TOKEN: set
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: dodeca-core 64-bit arm_blizzard_avalanche
Clang: 14.0.3 build 1403
Git: 2.39.2 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.88.1 => /usr/bin/curl
macOS: 13.4-arm64
CLT: 14.3.1.0.1.1683849156
Xcode: N/A
Rosetta 2: false