brew tips

隐藏

解决软件包安装缓慢的问题

brew作为macOS非常著名的安装包管理软件,使用非常方便,但需要解决经常出现安装缓慢的现象:

1. 修改homebrew仓库的拉取地址:

#see https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.c:qn/git/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

2. Brew设置

.zshrc.bashrc中添加:

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles # 某些软件包从镜像下载
export HOMEBREW_NO_AUTO_UPDATE=true  # 禁止自动更新

有些Brew软件下载链接在国外,比较慢,可以借助Socks加速,例如:

# 临时修改此环境变量加速Brew下载
export ALL_PROXY=http://127.0.0.1:1087

解决brew update慢的问题

以上是网上常见的解决brew慢的方法,但是brew update依然很慢,:(

brew update --verbose

通过这一步命令观察,发现问题卡在cask更新上,原来清华镜像没有cask镜像,所以改用ustc镜像:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-cask.git
-----EOF-----

Categories: programming Tags: brew tips