【解决 brew update 时间太久的问题】

文章介绍了如何解决使用brewupdate时因访问GitHub缓慢导致的长时间更新问题。解决方案包括更换Homebrew源,如使用清华大学开源软件镜像站,以及更换Homebrew-bottles镜像以提升软件下载速度。通过修改git远程仓库URL和设置环境变量HOMEBREW_BOTTLE_DOMAIN,可以有效提高在国内使用brew的效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

使用 brew install 时会触发 brew update,而update阶段主要是进行homebrew-cask 和 homebrew-core 及一些其他相关依赖的更新,这些依赖都托管在GitHub,由于国内网络访问GitHub本身就比较慢,做大文件下载的速度可想而知会更慢。

初步分析

使用brew update –verbose观察update过程:

# 执行命令
brew update --verbose

可以发现在从 GitHub fetch 资源时是最罪恶根源。

解决方案两步走

1、更换Homebrew源

目前国内比较好用的brew源有很多,比较推荐使用清华大学开源软件镜像站的,以下是详细配置

# brew 程序本身,Homebrew/Linuxbrew 相同
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 以下针对 mac OS 系统上的 Homebrew
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

# 以下这两个命令行可以不执行,不影响最终结果
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git

# 以下针对 Linux 系统上的 Linuxbrew
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/linuxbrew-core.git

配置完成后,可以到对应的目录下查看git remote配置,如:

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote -v

看到显示为如下的结果说明已经配置成功:

origin	https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (fetch)
origin	https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (push)

2、更换 Homebrew-bottles 镜像(影响软件下载速度)

临时替换

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles

永久替换

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

至此,已经完成了brew源的切换,可以运行brew update 测试是否正常。

另外,与上文无关的问题:
自己在 ~/.bashrc中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bashrc
发现zsh加载的是 ~/.zshrc文件,而 ‘.zshrc’ 文件中并没有定义任务环境变量。
解决办法:
在~/.zshrc文件最后,增加一行:
source ~/.bashrc

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值