目录
  1. 1. 问题发现
  2. 2. 问题解决
    1. 2.1. 更换源为阿里源
    2. 2.2. 更换为清华源
    3. 2.3. 更换homebrew-cask源
    4. 2.4. 切换回官方源
Homebrew 更新慢解决方法

在使用brew安装的时候一直卡在update brew阶段,下载文件极度缓慢(几 KB/s)

问题发现

在通过brew update --verbose观察update过程中,发现在从GitHub仓库获取文件的时候卡住,可能是由于国内访问github过慢导致。

问题解决

主要解决国内网络环境GitHub下载速度慢,我们可以更换homebrew的镜像源为国内源。

更换源为阿里源

1
# 替换brew.git:
2
cd "$(brew --repo)"
3
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
4
5
# 替换homebrew-core.git:
6
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
7
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
8
9
# 替换homebrew-bottles:
10
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
11
source ~/.zshrc

更换为清华源

自我感觉没有阿里源快

1
# 替换brew.git
2
cd "$(brew --repo)"
3
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
4
5
# 替换homebrew-core.git
6
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
7
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
8
9
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
10
source ~/.zshrc
11
12
# 刷新源
13
brew update

更换homebrew-cask源

阿里云的镜像站没有提供homebrew-cask,通过搜素发现USTC镜像站提供了homebrew-cask源。更换此源:

1
# 替换homebrew-cask.git:
2
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
3
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

切换回官方源

若发现替代后无反应,可以重置回官方源

1
重置brew.git:
2
cd "$(brew --repo)"
3
git remote set-url origin https://github.com/Homebrew/brew.git
4
5
重置homebrew-core.git:
6
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
7
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

注释掉bash配置文件里的有关Homebrew Bottles即可恢复官方源,重启bash或让bash重读配置文件。

文章作者: Izzio
文章链接: https://izzio.netlify.com/blog/software/mac/50309.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Seventy
ENG