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
相关推荐
仙剑魔尊重楼1 天前
iMazing 3.1.3官方中文版新功能介绍
macos·objective-c·cocoa
Genie cloud1 天前
在 Mac 上使用 Docker 安装宝塔并部署 LNMP 环境
macos·docker·容器·云计算
清蒸鳜鱼1 天前
【Mobile Agent——Droidrun】MacOS+Android配置、使用指南
android·macos·mobileagent
linweidong1 天前
屏幕尺寸的万花筒:如何在 iOS 碎片化生态中以不变应万变?
macos·ios·移动开发·objective-c·cocoa·ios面试·ios面经
TESmart碲视2 天前
如何用一套键盘鼠标切换多个输入设备?TESmart KVM热键工作原理深度解析.一份涵盖设计原理、使用方法与兼容性的完整技术指南
游戏·macos·计算机外设·kvm切换器·双屏kvm切换器
Roc.Chang2 天前
Cursor / VS Code 常用快捷键对比表(Windows / Linux / macOS)
linux·windows·vscode·macos
2601_949146532 天前
Objective-C短信验证码接口开发:封装一个基础的网络请求工具方法
macos·objective-c·cocoa
刘某某.2 天前
mac 上 WPS 公式字体不对
macos·wps
Feibo20112 天前
映射到本地mklink
python·macos
我是六月生2 天前
MacOS启动盘制作(可多合一),并实现MacOS降版本
macos