國內安裝Homebrew很慢,可以使用下面的方法:
curl -fsSL https://gitee.com/xueweihan/codes/vfrgh7z8qcjlx1ubwt6nk71/raw\?blob_name\=brew_install.sh >> brew_install
先把安裝文件保存到brew_install,然後修改其中的倉庫地址,打開 brew_install 文件,把
BREW_REPO後面引號內的地址改爲:
https://mirrors.ustc.edu.cn/brew.git
或者
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
如果有CORE_TAP_REPO,則把引號內的地址改爲:
https://mirrors.ustc.edu.cn/homebrew-core.git
或者
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
如果沒有CORE_TAP_REPO也不用新增。
執行下面的命令開始安裝:
/usr/bin/ruby brew_install
安裝到顯示:
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
時,可能會比較慢了,此時中斷安裝。手動執行:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
上面的git地址可以使用前面CORE_TAP_REPO的兩個地址中任意一個。
然後再把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
或者:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
安裝完成後再更新一下:
brew update
檢測一下是否有問題:
brew doctor
我的就檢測到一些警告,不過不影響。
爲了讓Homebrew安裝軟件時速度更快,需要替換Homebrew-bottles的地址,使用:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
臨時替換。如果Mac是終端用的bash,使用
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
進行永久替換,如果終端用的是zsh,把bash_profile改爲zshrc即可。
參考:
https://www.zhihu.com/question/35928898
https://blog.csdn.net/DiyHzp/article/details/90763558
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles/