本文轉(zhuǎn)載自:https://www.raydbg.com/2019/Homebrew-Update-Slow/,僅供個人學(xué)習(xí)參考使用。
近期使用Homebrew去下載安裝軟件的時候總是卡在update階段证逻,時間非常久巴碗,難以忍受嗜暴。記錄一下解決方法,
使用Homebrew安裝軟件的時候一直卡在Update階段基跑。同時發(fā)現(xiàn)從github.com下載文件也極度緩慢(幾十 KB/s)。
使用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.
Fromhttps://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
發(fā)現(xiàn)update卡在從github倉庫獲取文件的過程涩僻。這個結(jié)果與手動從github下載文件慢的癥狀相互印證栈顷。
由于問題主要是在國內(nèi)網(wǎng)絡(luò)環(huán)境github下載慢,因此嘗試:
更換使用國內(nèi)的homebrew鏡像源萄凤;
使用代理訪問github.com室抽。
使用以下命令更換國內(nèi)阿里云上的homebrew鏡像:
# 替換brew.git:
cd "$(brew --repo)"
git remote set-url originhttps://mirrors.aliyun.com/homebrew/brew.git
# 替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url originhttps://mirrors.aliyun.com/homebrew/homebrew-core.git
# 替換homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
替換后,問題依舊靡努,繼續(xù)查看日志:
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-core...
Fromhttps://mirrors.aliyun.com/homebrew/homebrew-core
+ 583b7f1...8435590 master? ? -> origin/master? (forced update)
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /usr/local/Homebrew/Library/Taps/caskroom/homebrew-fonts...
remote: Enumerating objects: 179429, done.
remote: Counting objects: 100% (179429/179429), done.
remote: Compressing objects: 100% (56607/56607), done.
Receiving objects:? 6% (11170/177189), 2.16 MiB | 30.00 KiB/s
可以看到由于homebrew-cask的倉庫依然指向了Github,這個過程還是慢兽泄。阿里云的鏡像站沒有提供homebrew-cask漓概,進(jìn)一步搜索找到USTC鏡像站,該站提供了homebrew-cask的源病梢。使用上述同樣的命令更換源:
# 替換homebrew-cask.git:
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url originhttps://mirrors.ustc.edu.cn/homebrew-cask.git
測試發(fā)現(xiàn)問題解決胃珍。
Note: Homebrew Bottles源的更換方法詳見這里蜓陌。
官方源地址:
https://github.com/Homebrew/brew.git
https://github.com/Homebrew/homebrew-core.git
https://github.com/Homebrew/homebrew-cask
家里的路由器已經(jīng)配置好了SS代理,只要簡單把github.com加入到黑名單強(qiáng)制走proxy就可以了钮热。然而代理速度一般,效果不及上述方法飒责。同時為了保證在其他網(wǎng)絡(luò)環(huán)境下的效率仆潮,保留方法一所做的修改读拆。
Donate
Post author:?Ray Wang
Post link:?http://www.raydbg.com/2019/Homebrew-Update-Slow/
Copyright Notice:?All articles in this blog are licensed under?BY-NC-SA?unless stating additionally.