修改 Homebrew 核心仓库地址是将 homebrew-core Git 仓库远程源从 GitHub 切换至国内镜像站以加速 brew update 和 install;需先确认并激活 homebrew/core Tap,再用 git -C 命令更换 origin URL,最后执行 brew update 验证生效。
修改 homebrew 核心仓库地址,本质是把 homebrew-core 这个 git 仓库的远程源从 github 切换到国内镜像站,从而加快 brew update 和 brew install 的速度。操作本身只需一行命令,但需确认当前环境是否已安装 core tap。
确认 homebrew-core 是否已存在
大多数用户安装 Homebrew 后会自动 tap homebrew-core,但仍建议先验证:
- 运行
brew tap,查看输出中是否包含homebrew/core - 若无,先执行
brew tap homebrew/core激活它
用 git 命令直接更换核心仓库远程地址
这是最通用、最稳定的方式,适用于所有镜像源(清华、中科大、阿里云等):
- 换为清华源:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git - 换为中科大源:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git - 换为阿里云源:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
刷新本地缓存并验证
改完地址后必须更新本地索引才能生效:
- 执行
brew update(首次可能耗时稍长,正常现象) - 检查是否成功:运行
git -C "$(brew --repo homebrew/core)" remote get-url origin,输出应为你刚设置的镜像 URL - 可顺手试装一个常用工具,如
brew install wget,确认下载走的是新源
补充说明:环境变量方式(适合长期固定使用)
如果你希望每次 brew update 都自动走指定源,可设置环境变量(推荐用于 M1/M2/M3 Mac):
- 编辑
~/.zprofile(或~/.bash_profile,取决于你用的 shell) - 添加三行(以清华源为例):
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"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" - 执行
source ~/.zprofile生效


















