常用的 Homebrew 国内镜像源
在国内使用 Homebrew 时,常常会遇到下载缓慢、超时的问题。目前许多国内大厂和高校都提供了镜像源,帮助开发者更高效地安装和管理软件包。
🧪
1. 清华大学 TUNA 镜像
Git 仓库镜像:
brew.git: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
homebrew-core.git: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
homebrew-cask.git: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
预编译 bottles 镜像:
HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
📍特点:官方镜像站维护较好,适合大部分用户使用。
配置命令:
# 替换 brew 源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换 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
# 设置 bottles(临时)
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
# 设置 bottles(永久,添加到 ~/.zshrc)
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
🐼
2. 中国科学技术大学 USTC 镜像
Git 仓库镜像:
brew.git: https://mirrors.ustc.edu.cn/brew.git
homebrew-core.git: https://mirrors.ustc.edu.cn/homebrew-core.git
homebrew-cask.git: https://mirrors.ustc.edu.cn/homebrew-cask.git
bottles 镜像:
HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
📍特点:国内访问速度也很快,适合替代官方源。
配置命令:
# 替换 brew 源
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替换 core
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替换 cask
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 设置 bottles(临时)
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
# 设置 bottles(永久,添加到 ~/.zshrc)
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
☁️
3. 阿里云镜像
Git 仓库镜像:
brew.git: https://mirrors.aliyun.com/homebrew/brew.git
homebrew-core.git: https://mirrors.aliyun.com/homebrew/homebrew-core.git
预编译 bottles 镜像:
HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew-bottles
📍特点:阿里云镜像站也提供 Homebrew 镜像,可用来替换官方源提高速度。
配置命令:
# 替换 brew 源
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换 core
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 设置 bottles(临时)
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew-bottles
# 设置 bottles(永久,添加到 ~/.zshrc)
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew-bottles' >> ~/.zshrc
📌
镜像覆盖内容
这些国内源一般会提供:
brew 本身的源码镜像
homebrew-core 核心配方仓库镜像
homebrew-cask(部分镜像站)应用程序安装包仓库镜像
bottles(预编译二进制包)镜像 👆
💡换了这些以后 brew update、brew install 都能明显快很多。
💡
使用场景
| 需求 | 推荐镜像 |
|---|---|
| 安装 Homebrew(全套) | 清华 / USTC / 阿里 |
| 更新 Formula 索引 | 清华 / USTC / 阿里 |
| 下载预编译 bottles 包 | 清华 / USTC / 阿里 |
🛠
快速切换示例(以清华为例)
以下是一套完整的切换命令,按顺序执行即可将 Homebrew 切换到清华大学镜像源:
# 替换 brew 源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换 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
# 设置 bottles
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
# 使环境变量生效
source ~/.zshrc
# 更新 Homebrew
brew update
💡提示:如果使用 bash,请将 ~/.zshrc 替换为 ~/.bash_profile 或 ~/.bashrc。
镜像拉取常见问题
使用与功能问题
错误码与失败问题
manifest unknown 错误:镜像不存在或标签错误
manifest unknown 错误
TLS/SSL 证书验证失败:Docker pull 时 HTTPS 证书错误
TLS 证书验证失败
DNS 解析超时:无法解析镜像仓库地址或连接超时
DNS 解析超时
410 Gone 错误:Docker 版本过低导致协议不兼容
410 错误:版本过低
402 Payment Required 错误:流量耗尽错误提示
402 错误:流量耗尽
401 UNAUTHORIZED 错误:身份认证失败或登录信息错误
身份认证失败错误
429 Too Many Requests 错误:请求频率超出专业版限制
429 限流错误
Docker login 凭证保存错误:Cannot autolaunch D-Bus(不影响登录)
凭证保存错误
账号 / 计费 / 权限
用户好评
来自真实用户的反馈,见证轩辕镜像的优质服务