一、安装依赖
在命令行输入
xcode-select --install
安装CLT for Xcode。
二、从国内镜像下载脚本并安装
设置环境变量
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
下载脚本并安装
curl -O https://cdn.jsdelivr.net/gh/Homebrew/install@master/install.sh
bash install.sh
三、配置从国内镜像更新
配置Homebrew源
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
配置Homebrew Core源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
配置Homebrew Cask源(可选)
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
配置Homebrew Services源(可选)
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-services"
git remote set-url origin https://gitcode.net/mirrors/Homebrew/homebrew-services.git
配置Homebrew Bottles源
#Bash
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
参考:
1、http://mirrors.ustc.edu.cn/help/brew.git.html
2、http://mirrors.ustc.edu.cn/help/homebrew-core.git.html
3、http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html
4、http://mirrors.ustc.edu.cn/help/homebrew-bottles.html
5、https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
6、https://gitcode.net/mirrors/Homebrew/homebrew-services