美文网首页
解决Homebrew下载更新极慢的问题

解决Homebrew下载更新极慢的问题

作者: 苦海飘摇 | 来源:发表于2020-11-18 16:12 被阅读0次

近期使用Homebrew去下载安装软件的时候总是卡在update阶段,时间非常久,难以忍受。记录一下解决方法,

症状

使用Homebrew安装软件的时候一直卡在Update阶段。同时发现从github.com下载文件也极度缓慢(总是卡住不动了)。

问题定位

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

brew update --verbose
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/caskroom/homebrew-fonts...
Fetching /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
remote: Enumerating objects: 337, done.
remote: Counting objects: 100% (337/337), done.
remote: Compressing objects: 100% (88/88), done.
remote: Total 298 (delta 221), reused 287 (delta 210), pack-reused 0
Receiving objects: 100% (298/298), 50.91 KiB | 39.00 KiB/s, done.
Resolving deltas: 100% (221/221), completed with 39 local objects.
From https://github.com/Homebrew/homebrew-core
   65a45a9..583b7f1  master     -> origin/master
remote: Enumerating objects: 179429, done.
remote: Counting objects: 100% (179429/179429), done.
remote: Compressing objects: 100% (56607/56607), done.
Receiving objects:   4% (7628/177189), 1.48 MiB | 8.00 KiB/s

发现update卡在从github仓库获取文件的过程。这个结果与手动从github下载文件慢的症状相互印证。

解决

由于问题主要是在国内网络环境github下载慢,因此尝试:

  1. 更换使用国内的homebrew镜像源;
  2. 使用代理访问github.com。

更换Homebrew源

使用以下命令更换国内阿里云上的homebrew镜像:

# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

# 替换homebrew-cask.git:
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 替换homebrew-bottles:
# echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
# source ~/.zshrc

若出现以下报错

==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
Already downloaded: /Users/luqin/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
Error: Checksum mismatch.
Expected: b065e5e3783954f3e65d8d3a6377ca51649bfcfa21b356b0dd70490f74c6bd86
  Actual: 8a1c8d4b86c749d7c5762367a92fbe80322af665e57d2bbf0665f57921cf8b9b
 Archive: /Users/luqin/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
To retry an incomplete download, remove the file above.
Error: Failed to upgrade Homebrew Portable Ruby!

解决

# 报/Users/luqin/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz文件错误,直接删掉即可,系统会重新下载该文件
sudo rm -rf /Users/luqin/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz

 ~> brew update --verbose
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/adoptopenjdk/homebrew-openjdk...
Fetching /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/phinze/homebrew-cask...
Updating /usr/local/Homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to and reset branch 'master'
Your branch is up to date with 'origin/master'.
Switched to and reset branch 'stable'
Current branch stable is up to date.

==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
######################################################################### 100.0%
==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
Already up-to-date.

测试发现问题解决。

参考:心之伊始

相关文章

网友评论

      本文标题:解决Homebrew下载更新极慢的问题

      本文链接:https://www.haomeiwen.com/subject/qsmciktx.html