本文介绍如何将 HomeBrew 的下载源更换为国内镜像(中国科学技术大学镜像站),显著提升包下载速度,解决国内访问 GitHub 资源缓慢的问题。

1️⃣ 更换下载源为 中国科学技术大学镜像站

# 新建 homebrew-cask 文件夹,若已经存在则无需新建
mkdir "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
# 将三个目录作为安全目录目录添加到全局的 Git 配置中
git config --global --add safe.directory "$(brew --repo)"
git config --global --add safe.directory "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git config --global --add safe.directory "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
# 更新 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

2️⃣ 选择 zsh 或 bash 用户,执行即可

  • 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

3️⃣ 更新 brew

brew update -v

配置完成