正題開始之前, 如果對 Homebrew 不太了解, 這里有一篇很好的介紹文章: macOS 包管理工具 Homebrew 不完全指南 花個幾分鍾讀一下, 絕對超值!
正題
Homebrew 通過 Git 來工作的, 默認的源是 Github. 因為眾所周知的原因, update
超級慢!
通過brew update -v
可以查看update
執行的詳細信息, 找到究竟是哪一步比較慢(管他哪一步慢, 往下看
解決辦法無外乎兩種: 1. 切換成國內源 2. 走 Proxy
這里采用第一種方法, 步驟如下:
- 替換 brew.git:
# 切換到 Homebrew 目錄 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-bottles: 二進制文件, **注意自己機器上使用的 SHELL **
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc source ~/.zshrc
- 替換 homebrew-cask.git: cask 表示 GUI 應用的源, 阿里雲沒有提供 cask 源, 故使用 USTC 源
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
切換成國內源之后, update 起來如絲般順滑 😃
如果不爽可以隨時改回去, 以下是官方源:
- https://github.com/Homebrew/brew.git
- https://github.com/Homebrew/homebrew-core.git
- https://github.com/Homebrew/homebrew-cask
完~~~