brew install 会先去执行 brew update
而 brew update,会依次更新
brew
homebrew-core
homebrew-cask
而以上三个的来源都在 github,国内 github 的连接极不稳定,国此速度才会很慢
最直观的解决方法,就是不从 github 更新。而走别的境像源,可以选择第三方的源,或是建立本地境像。
建立本地境象的方法:
cd ~/Documents
mkdir repository
cd repository
git clone --mirror https://github.com/Homebrew/brew.git
git clone --mirror https://github.com/Homebrew/homebrew-core.git
git clone --mirror https://github.com/Homebrew/homebrew-cask.git
cd /usr/local/Homebrew/
git remote set-url origin ~/Documents/repository/brew.git
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote set-url origin ~/Documents/repository/homebrew-core.git
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
git remote set-url origin ~/Documents/repository/homebrew-cask.git
优点:由于镜像在本地,等同于完全跳过了 update 阶段,安装很顺畅
缺点:需要手动同步境像,不过对于 brew 这类实时性要求不高的软件来说,这可能也是一个优点
cd ~/Documents/repository/brew.git
git remote update
cd ~/Documents/repository/homebrew-core.git
git remote update
cd ~/Documents/repository/homebrew-cask.git
git remote update
brew update