mac修改homebrew核心库镜像本质是将git远程地址替换为国内镜像站(如清华源),需分别执行三条git命令更新brew主仓库、homebrew-core及homebrew/cask的origin地址,换源后运行brew update即可加速同步。
mac 修改 homebrew 核心库(homebrew-core)的下载镜像,本质是把 git 远程仓库地址从默认的 github 换成国内镜像站(如清华、中科大),让 brew update 和 brew install 能快速拉取配方(formula)。
下面分三类常见场景说明,操作前请确保已成功安装 Homebrew(哪怕只是半途卡住,只要 /opt/homebrew 或 /usr/local/Homebrew 目录存在,就可继续):
一、已装好 Homebrew,想立刻换源
执行这三条命令即可(推荐清华源,稳定且同步及时):
-
替换主仓库(brew 自身):
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
-
替换核心公式库(homebrew-core):
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
-
替换桌面应用库(cask,可选但建议一起换):
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
换完后运行 brew update,你会看到明显加速——不再是卡在 “Updating Homebrew”,而是几秒内完成同步。
二、安装中途失败,core 仓库没拉下来
常见于执行官方脚本时卡在 Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-core'。此时可以手动补全:
-
先创建目录结构(路径按你的芯片自动适配):
mkdir -p "$(brew --repo)/Library/Taps/homebrew" cd "$(brew --repo)/Library/Taps/homebrew"
-
然后直接克隆清华镜像:
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
-
如果还缺 cask,顺手也加上:
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
再运行 brew update,通常就能正常继续了。
三、确认是否生效 & 快速验证
换源后建议检查两处:
-
查看 brew 主仓库地址:
git -C "$(brew --repo)" remote -v
输出中
origin行应显示https://mirrors.tuna.tsinghua.edu.cn/.../brew.git -
查看 homebrew-core 地址:
git -C "$(brew --repo homebrew/core)" remote -v
同样应指向清华镜像的
homebrew-core.git
最后试装一个小工具验证流程通不通:
brew install wget
如果几秒内开始下载并完成,说明核心库镜像已起效。
不复杂但容易忽略










