Mac上用阿里云镜像源加速Homebrew需三步:替换brew.git、homebrew-core.git等Git地址;配置HOMEBREW_API_DOMAIN和HOMEBREW_BOTTLE_DOMAIN指向阿里云;按shell类型(zsh/bash)写入对应配置文件并source生效,最后brew update验证。
mac 上用阿里云镜像源加速 homebrew,核心是让三类资源走国内服务器:homebrew 自身代码(brew.git)、软件配方仓库(homebrew-core.git)和预编译二进制包(homebrew-bottles)。新版本 homebrew 已转向 api 优先模式,还需额外配置 homebrew_api_domain,否则 brew update 仍会访问海外接口。
确认 Shell 类型再操作
Homebrew 配置依赖你的默认 shell,先运行以下命令查看:
echo $SHELL
结果为 /bin/zsh(macOS Catalina 及以后默认)就操作 ~/.zshrc;若为 /bin/bash,则操作 ~/.bash_profile。
替换 Git 仓库地址
这一步更新 Homebrew 自身和软件配方的元数据来源,避免每次 brew update 都去 GitHub 拉取:
- 替换 brew 主仓库:
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git - 替换核心软件仓库:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git - 如有使用 cask(图形应用),也建议同步替换:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
配置 API 和 Bottle 域名(关键)
仅改 Git 地址不够。新版 Homebrew 通过 API 获取软件信息,并从 HOMEBREW_BOTTLE_DOMAIN 下载二进制包。必须设置这两个环境变量:
对 zsh 用户(推荐):
- echo 'export HOMEBREW_API_DOMAIN="https://mirrors.aliyun.com/homebrew-bottles/api"' >> ~/.zshrc
- echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles"' >> ~/.zshrc
- source ~/.zshrc
对 bash 用户:
- 把上面两行中的
~/.zshrc换成~/.bash_profile,最后执行 source ~/.bash_profile
验证与生效
执行以下命令完成更新并检查是否生效:
- brew update —— 触发完整同步,首次可能稍慢但后续极快
-
brew config —— 查看输出中:
-
ORIGIN应显示阿里云地址(如https://mirrors.aliyun.com/homebrew/brew.git) -
Core tap ORIGIN同样指向阿里云 -
HOMEBREW_API_DOMAIN和HOMEBREW_BOTTLE_DOMAIN均为阿里云域名
-
全部匹配即配置成功。之后 brew install 将从国内镜像高速下载索引与二进制包,告别 KB/s 级等待。

















