使用国内镜像源安装Homebrew

本文使用【中科大镜像】进行安装

1. 确认、安装 Command Line Tools

1
xcode-select --install

2. 设置镜像环境变量(当前终端)

1
2
3
4
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"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"

3. 运行安装脚本

1
/bin/bash -c "$(curl -fsSL https://mirrors.ustc.edu.cn/misc/brew-install.sh)"

中途输入密码、按回车,直到出现 Installation successful!

4. 配置 PATH 与镜像(永久生效)

1
2
3
4
5
6
7
8
9
10
echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >> ~/.zprofile
# 注意,如果是 Intel 版本 mac,需要调整这里的路径为
# echo 'eval "$(/usr/local/bin/brew shellenv zsh)"' >> ~/.zprofile

echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.zprofile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"' >> ~/.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.zprofile
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >> ~/.zprofile

source ~/.zprofile

5. 验证

1
2
brew --version
brew config

brew config 中镜像地址显示为 mirrors.ustc.edu.cn 即配置成功。