homebrew 在国内变慢的根本原因是其 brew.git、homebrew-core.git 和 homebrew-bottles 三部分默认托管于海外服务器,需全部切换至国内镜像源(如清华或中科大)才能真正提速。

Homebrew 在国内用得慢,根本原因不是它本身有问题,而是它的三个核心部分——brew.git、homebrew-core.git 和 homebrew-bottles——默认都托管在海外服务器上。换源不是“换个地址试试”,而是把这三块全部指向国内镜像站,才能真正提速。
搞清楚要换哪三处
Homebrew 的下载和更新流程分三步走,每一步都可能卡在海外:
-
brew 自身代码:即 Homebrew 程序本体,存放在
brew.git仓库。执行brew update时,第一步就是更新它。 -
软件配方库:也就是
homebrew-core.git,里面是所有命令行工具(如 git、python、curl)的安装脚本。没它,brew install就不知道怎么装。 -
预编译二进制包(bottles):这不是 Git 仓库,而是一个域名。Homebrew 默认从
https://ghcr.io或旧的homebrew.bintray.com下载已编译好的安装包。大软件(比如 node、rust)走这路,能省几小时编译时间。
清华源配置(推荐稳定用户)
清华大学 TUNA 镜像同步频率高(通常延迟 ≤2 小时),教育网/三大运营商访问都稳。按顺序执行以下命令:
- 换 brew 核心:
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git - 换 core 公式库:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git - 设 bottles 域名:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc && source ~/.zshrc
Apple Silicon(M1/M2/M3)用户注意:确保终端使用的是 zsh,并确认 ~/.zshrc 已生效;若用 bash,请改写入 ~/.bash_profile。
中科大源(适合教育网或联通用户)
中科大镜像采用 CDN 加速,部分地区实测比清华源更快。替换命令只需把域名换成 https://mirrors.ustc.edu.cn:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.gitgit -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.gitecho 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc && source ~/.zshrc
验证与排错关键点
配置完别急着装软件,先验证是否真生效:
- 运行
brew config | grep -E "BOTTLE|Core tap ORIGIN",输出里应出现清华或中科大的域名,而不是 github.com - 执行
brew update,观察是否秒级完成,而非卡在 “Updating Homebrew…” 十几分钟 - 如果仍慢,检查是否漏写了
source ~/.zshrc;或者终端启动时加载了错误的 shell 配置文件(比如 iTerm 用了 zsh,VS Code 终端却用了 bash) - 偶尔遇到同步延迟,可等一小时再试;若长期失效,说明镜像站临时维护,可临时切到阿里云源:
https://mirrors.aliyun.com/homebrew-bottles










