直接换源可明显提速,需将brew核心、homebrew-core、homebrew-cask、bottles四个部分全部切换至国内镜像(如清华或中科大),并配置HOMEBREW_BOTTLE_DOMAIN、HOMEBREW_API_DOMAIN等环境变量,缺一不可。
直接换源就能明显提速,关键是把四个核心部分都切到国内镜像,缺一不可。
确认当前 Homebrew 状态
打开终端,先检查是否已安装并运行正常:
- 输入 brew --version,有版本号说明已装好
- 若提示
command not found,需先安装:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - 执行 brew doctor 确保无基础报错
一次性切换全部核心源(推荐清华或中科大)
新版 Homebrew 涉及四个关键组件:brew 核心、homebrew-core、homebrew-cask、bottles 二进制包。只换其中一两个,仍会卡在其他环节。
-
清华镜像(同步快、稳定性高):
cd "$(brew --repo)" && git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.gitcd "$(brew --repo homebrew/core)" && git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.gitcd "$(brew --repo homebrew/cask)" && git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git -
中科大镜像(CDN覆盖广、响应快):
把上面三行中的https://mirrors.tuna.tsinghua.edu.cn/...全部替换成https://mirrors.ustc.edu.cn/...(注意路径格式差异,中科大不用/git/)
必须配置环境变量(新版加速关键)
2024 年起,Homebrew 默认通过 API 获取元数据,仅改 Git 地址不够,还需设置 API 和 bottles 域名:
- 编辑配置文件:
zsh 用户:运行nano ~/.zshrc
bash 用户:运行nano ~/.bash_profile - 在文件末尾添加以下内容(以中科大为例,清华用户将域名统一替换为
https://mirrors.tuna.tsinghua.edu.cn):# Homebrew 国内加速export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"export HOMEBREW_NO_ENV_HINTS="1" - 保存退出后,立即生效:
zsh:运行source ~/.zshrc
bash:运行source ~/.bash_profile
验证与后续操作
全部配置完成后,执行:
- brew update —— 首次较慢,但应不再卡在 GitHub;成功后无报错即生效
- brew tap | head -3 —— 查看当前 tap 是否已指向国内源
- brew install hello —— 小试一把,观察下载速度和完成时间
- 如需恢复官方源,只需把 git remote 地址和环境变量注释掉或删掉,再
source即可


















