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
相关推荐
Bigger9 小时前
Tauri(21)——窗口缩放后的”失焦惊魂”,游戏控制权丢失了
前端·macos·app
Bigger9 小时前
Tauri (20)——为什么 NSPanel 窗口不能用官方 API 全屏?
前端·macos·app
Wcowin20 小时前
Mac Shell 环境优化指南
macos·职场和发展·蓝桥杯
止礼20 小时前
FFmpeg8.0.1 Mac环境 CMake本地调试配置
macos·ffmpeg
sean90821 小时前
Colima 下 docker pull 失败自查流程
macos·docker·容器·colima
denggun123452 天前
卡顿监测原理
macos·ios·xcode
Sheffi662 天前
iOS 触摸事件完整传递链路:Hit-Test 全流程深度解析
macos·ios·cocoa
ChineHe2 天前
Gin框架入门篇002_第一个Gin服务
macos·xcode·gin
Roc.Chang2 天前
解决 macOS 26.1 The application “xxxx” can’t be opened. 问题
macos
赶路人儿2 天前
从intel mac迁移到M3后软件的兼容性
macos