自2023-02-16发布的 Homebrew 4.0.0 起,Homebrew终于抛弃了使用Git的方式维护软件信息而采用JSON文件的方式,这也意味着 HOMEBREW_INSTALL_FROM_API
会成为默认的行为。因此对于大部分用户来说不再需要homebrew/core
仓库,而会新引入homebrew/api
仓库。
网上众多介绍更换homebrew
镜像源的文章都已经过时了,这里记录下最新的操作方式
-
手动清理下不再使用的Homebrew tap信息,会释放空间,后续执行
brew update
好像也会默认执行brew untap homebrew/cask brew untap homebrew/core
-
设置brew镜像源
这个只需要执行一次,会帮忙设置
git remote
,所以不需要加到~/.zshrc
里面export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git" brew update
这一步也可以手动设置,效果是一样的
cd "$(brew --repo)" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
-
设置API访问地址
4.0.0版本之后换成了API方式,动态请求网络(默认为
https://formulae.brew.sh/api
)获得JSON文件,请求的地址需要以环境变量的形式来指定(如果使用的是bash,则将.zshrc
修改为.bashrc
)echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.zshrc source ~/.zshrc brew update
-
设置
homebrew-service
、homebrew-cask-fonts
、homebrew-cask-versions
、homebrew-command-not-found
的镜像源(这些不一定都有用到)brew tap --custom-remote --force-auto-update homebrew/cask-fonts https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git brew tap --custom-remote --force-auto-update homebrew/cask-versions https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git brew tap --custom-remote --force-auto-update homebrew/command-not-found https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-command-not-found.git brew tap --custom-remote --force-auto-update homebrew/services https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-services.git brew update
重要参考了清华大学的Homebrew 镜像源使用帮助 ,写得非常详细,此外也可以考虑使用中科大的Homebrew镜像。