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 小时前
XMind for Mac v24.01.dmg 安装教程(Mac思维导图软件下载安装步骤)
macos·xmind
醇氧11 小时前
Mac 安装 Docker Desktop
macos·docker·容器
神秘人-解说13 小时前
在Mac上安装Windows 11/10双系统(M1/M2/Intel通用)
windows·macos·mac安装双系统·mac安装虚拟机·mac安装windows
知难行难14 小时前
macOS配置Apocrita及ssh访问及获取GPU权限
运维·macos·ssh
游戏开发爱好者818 小时前
Mac 抓包软件怎么选?从 HTTPS 调试、TCP 数据流分析到多工具协同的完整抓包方案
tcp/ip·macos·ios·小程序·https·uni-app·iphone
马拉萨的春天19 小时前
iOS中广告SDK如何判断一个广告是否真实展示
macos·ios·cocoa
心灵宝贝1 天前
Mac 安装 JDK 8u281(JDK-8u281-1.dmg)详细步骤(附安装包)
java·macos·intellij-idea
侯小啾1 天前
理解计算机网络中的MAC地址
网络·计算机网络·macos·mac
坚果派·白晓明2 天前
开源鸿蒙终端工具Termony构建HNP包指导手册Mac版
macos·开源·harmonyos