只需执行四条命令即可切回GitHub官方源:依次还原brew、homebrew-core、homebrew-cask的远程地址,并清除HOMEBREW_BOTTLE_DOMAIN等镜像环境变量,最后运行brew update验证。
直接执行几条命令就能切回 github 官方源,不需要重装或手动删文件。关键是要把之前换源时改过的三处全部还原:主仓库(brew)、核心公式库(homebrew-core)、cask 应用库(homebrew-cask),以及可能设置的环境变量(如 homebrew_bottle_domain 或 homebrew_api_domain)。
还原 Git 仓库远程地址
这一步把 brew、homebrew-core 和 homebrew-cask 的 remote URL 改回官方 GitHub 地址:
-
主仓库(brew):
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git -
核心公式库(homebrew-core):
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git -
Cask 库(homebrew-cask):
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
清除镜像相关的环境变量
检查你的 shell 配置文件(~/.zshrc 或 ~/.bash_profile),删掉或注释掉类似以下的行:
export HOMEBREW_BOTTLE_DOMAIN=...export HOMEBREW_API_DOMAIN=...-
export HOMEBREW_CORE_GIT_REMOTE=...(旧版可能有)
删完后运行 source ~/.zshrc(或对应配置文件)让改动生效。
让 macOS 自动化像说话一样简单 —— 用代码控制你的 Mac,无需学习 AppleScript 系统要求 macOS 14+ (Sonoma) Python 3.9+ 需要开启:辅助功能 + 屏幕录制权限
刷新并验证是否成功
执行以下命令更新本地索引,并确认已连上官方源:
-
brew update—— 正常应显示从github.com/Homebrew/...拉取更新 -
brew --version—— 确保命令仍可用 -
brew tap-info homebrew/core—— 输出中homepage应为https://github.com/Homebrew/homebrew-core
小提示:遇到报错怎么办?
如果 brew update 报 “ref not found” 或 “detached HEAD”,说明本地仓库状态异常。可强制重置:
cd "$(brew --repo)" && git fetch && git reset --hard origin/mastercd "$(brew --repo homebrew/core)" && git fetch && git reset --hard origin/master
完成后再次 brew update 即可。

















