Homebrew更换为中国大陆镜像源
作为MacOS上的软件包管理工具,Homebrew是依托于Github的。由于后者在国内访问的不稳定性,在中国大陆的网络环境下执行brew update / brew upgrade / brew cask upgrade 等命令,一般会长时间无响应。
此时可以考虑将homebrew的源替换为中国大陆的镜像源,一般由大学托管。
一、替换homebrew镜像源
以下以中科大的homebrew镜像源为例进行说明,其他镜像源地址可以自行搜索。
1. 替换 brew.git为中科大镜像源
$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
或者写到一行上:
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
2. 替换 homebrew-core.git为中科大镜像源
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
或者写到一行上:
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
3. 替换 homebrew-cask.git为中科大镜像源
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
$ git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-cask.git
二、重置 Homebrew 镜像源
下列命令分别将brew.git,homebrew-core.git和homebrew-cask.git切回官方原始镜像(GitHub)。
$ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core
$ git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" remote set-url origin https://github.com/Homebrew/homebrew-cask
参考资料
[1] 简书|Homebrew切换镜像源(中科大&清华镜像)
[2] 中国科学技术大学开源软件镜像|Homebrew Cask 源使用帮助
本文固定链接: https://blog.xieyc.com/homebrew-change-china-source-mirror/ | 小谢的小站