换源/Homebrew
Homebrew 镜像源
Homebrew 的国内镜像(API / bottles / 仓库全套),brew install 提速。
Homebrew 的 API、bottles 与公式仓库都在 GitHub,国内直连慢;镜像通过环境变量接管。设置后需 brew update-reset 才生效,个别 formula 仍回官方。
可用镜像源(7)
换源方法
环境变量(清华源,推荐)
写入 ~/.zshrc(bash 用户写 ~/.bash_profile)
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"重置已克隆的仓库后生效
brew update-reset
brew update常见问题
设置后仍走 GitHub?
需 brew update-reset 重置已克隆仓库,再 brew update。
某些 formula 失败?
个别 bottle 未镜像,回官方或源码编译。
如何还原?
unset 相关环境变量后 brew update-reset。
使用提示
- ·换源前备份原配置(`/etc/apt/sources.list`、`*.repo` 等),出问题可回滚。
- ·保留官方 security 源,避免镜像同步延迟导致安全补丁晚到。
- ·发行版版本代号(noble/bookworm 等)要与镜像目录一致,别混用。
- ·企业内网可能强制 DNS / 代理,换源后仍慢先排查网络出口。