mac电脑brew update很慢咋办?

大概率是源的问题,要换成国内的源,但因为Homebrew 早就切换到 API 优先模式,默认不再克隆完整的 homebrew-core git 仓库,而是通过 API 拉取软件包元数据,所以本地可能没有传统的 homebrew-core 目录。所以不能按照老办法更新源。(老办法划了删除线,如果是之前的版本也是可以用的)

核心逻辑

API 模式下,切换镜像源的核心是让 Homebrew 的 API 请求指向国内镜像(而非 GitHub)

1、配置 brew 核心仓库镜像(基础前提)

bash 复制代码
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

2、配置 API 镜像源(关键步骤,替代传统 git 仓库配置)

bash 复制代码
# 对于 zsh 用户(默认)
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.zshrc
# 对于 bash 用户
# echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.bash_profile

# 生效配置
source ~/.zshrc  # 或 source ~/.bash_profile

确认自己是zsh还是bash用户的命令:echo $SHELL

3、测试更新

brew update --verbose

4、执行更新:brew update


以前更新源的方法

目前,清华大学的镜像源是 Homebrew 国内用户中最稳定和推荐的选择

步骤1:请按照以下命令,在终端中执行,以更换为清华大学镜像源:

bash 复制代码
# 替换 brew.git
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 替换 homebrew-core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

# 替换 homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

# 替换 homebrew-cask-versions.git
git -C "$(brew --repo homebrew/cask-versions)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git

# 替换 homebrew-services.git
git -C "$(brew --repo homebrew/services)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-services.git

# 设置 bottle 镜像(针对 zsh 用户)
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

# 如果是 bash 用户,请使用下面两行代替上面两行
# echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bashrc
# source ~/.bashrc

步骤 2:清理并手动更新

更换完镜像源后,执行清理命令,然后手动触发一次更新,这将帮助 Homebrew 重新建立缓存。

bash 复制代码
# 清理旧的缓存和下载
brew cleanup

# 手动更新 Homebrew
brew update
相关推荐
林疏safe37 分钟前
CAD2026最新mac的安装教程收集免费分享
macos
Digitally1 小时前
如何高效安全地将 iPhone 与 Mac 同步
安全·macos·iphone
程序员允诺1 小时前
办公 WiFi 二次隔离下的远程桌面解决方案实践(Mac → Win11)
macos
hudawei9961 小时前
win和Mac在创建python虚拟环境,启动环境等操作的异同
windows·python·macos·虚拟环境
2501_916008891 小时前
没有 Mac 如何在 Windows 上创建 iOS 应用描述文件
android·macos·ios·小程序·uni-app·iphone·webview
提笔忘字的帝国12 小时前
【教程】macOS 如何完全卸载 Java 开发环境
java·开发语言·macos
数据雕塑家18 小时前
【网络故障排查实战】多台机器互ping异常:MAC地址冲突引发的网络“薛定谔猫“现象
网络·macos
TheNextByte11 天前
将照片从Mac传输到Android 7 种可行方法
android·macos·gitee
提笔忘字的帝国1 天前
【2026版】macOS 使用 Homebrew 快速安装 Java 21 教程
java·开发语言·macos
洪大宇1 天前
Mac 使用蓝牙功能
macos