解決Mac上國內安裝HomeBrew慢的解決方法。以下git
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
複製代碼
獲取官網腳本並保存名爲 brew_install:raw.githubusercontent.com/Homebrew/in…github
打開 brew_install 文件,修改以下:shell
找到以下代碼:ruby
BREW_REPO = 「https://github.com/Homebrew/brew「.freeze
CORE_TAP_REPO = 「https://github.com/Homebrew/homebrew-core「.freeze
複製代碼
更改成:bash
BREW_REPO = 「https://mirrors.ustc.edu.cn/brew.git 「.freeze
CORE_TAP_REPO = 「https://mirrors.ustc.edu.cn/homebrew-core.git「.freeze
複製代碼
注意: 新版本HomeBrew可能沒有CORE_TAP_REPO
這句代碼,若是沒有不用新增。 若是這個鏡像有問題的話,能夠換成其餘源。app
打開終端容許腳本curl
/usr/bin/ruby brew_install
複製代碼
若是此時腳本應該停在ui
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
複製代碼
出現這個緣由是由於源不通,代碼來不下來,解決方法就是更換國內鏡像源:url
手動執行下面這句命令,更換爲中科院的鏡像:spa
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
複製代碼
而後把homebrew-core的鏡像地址也設爲中科院的國內鏡像
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
複製代碼
執行更新,成功:
brew update
複製代碼
最後用這個命令檢查無錯誤:
brew doctor
複製代碼
至此HomeBrew就安裝完成了。
直接使用 Homebrew 還須要更改默認源。如下是將默認源替換爲國內 USTC 源的方法。 以下:
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/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
複製代碼
bash(默認 shell)用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
複製代碼
zsh 用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
複製代碼