Mac brew update 慢~~~


正題開始之前, 如果對 Homebrew 不太了解, 這里有一篇很好的介紹文章: macOS 包管理工具 Homebrew 不完全指南 花個幾分鍾讀一下, 絕對超值!

正題

Homebrew 通過 Git 來工作的, 默認的源是 Github. 因為眾所周知的原因, update超級慢!

通過brew update -v可以查看update執行的詳細信息, 找到究竟是哪一步比較慢(管他哪一步慢, 往下看

解決辦法無外乎兩種: 1. 切換成國內源 2. 走 Proxy

這里采用第一種方法, 步驟如下:

  1. 替換 brew.git:
    # 切換到 Homebrew 目錄
    cd "$(brew --repo)"
    # 切換成阿里源, 其實就是改了遠程倉庫的地址
    git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
    
  2. 替換 homebrew-core.git:
    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
    
  3. 替換 homebrew-bottles: 二進制文件, **注意自己機器上使用的 SHELL **
    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
    source ~/.zshrc
    
  4. 替換 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 起來如絲般順滑 😃

brew update -v

如果不爽可以隨時改回去, 以下是官方源:

  1. https://github.com/Homebrew/brew.git
  2. https://github.com/Homebrew/homebrew-core.git
  3. https://github.com/Homebrew/homebrew-cask

完~~~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM