Homebrew官方的源一般下载包之类的速度会很慢,通常用国内的镜像源来代替,提高效率。
Homebrew主要由四部分组成:

名称 说明
brew Homebrew源代码仓库
homebrew-core Homebrew核心软件仓库
homebrew-bottles Homebrew预编译二进制软件包
homebrew-cask MacOS客户端应用

目前国内镜像源主要有:中科大镜像、阿里镜像、清华镜像
首先查看本地的镜像源地址,命令行输入如下内容:

查看brew.git当前源
cd "$(brew --repo)" && git remote -v

查看homebrew-core.git当前源
cd "$(brew --repo homebrew/core)" && git remote -v

若输出以下内容,则不是本地镜像源,可以更换
Homebrew更换国内镜像源_git

切换Homebrew镜像源为中科大镜像源

替换brew.git

cd "$(brew --repo)" && git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

替换homebrew-core.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

替换homebrew-cask.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

zsh 替换homebrew-bottles镜像,Mac OS在10.15系统开始,默认的shell都换成了zsh

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc

修改使其立即生效

source ~/.zshrc

bash 替换homebrew-bottles镜像

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile

修改使其立即生效

source ~/.bash_profile

刷新源

brew update

检查,结果如下图,更改成功!
Homebrew更换国内镜像源_预编译_02

参考文章链接: Homebrew更换国内镜像源(中科大、阿里、清华)