用到的镜像:
https://gitee.com/mirrors/homebrew.git
https://gitee.com/jinxin.70/homebrew-core.git
https://gitee.com/jinxin.70/homebrew-cask.git
1、安装前准备:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
echo 'export HOMEBREW_CORE_GIT_REMOTE=https://mirrors.aliyun.com/homebrew/homebrew-core.git' >> ~/.bash_profile
source ~/.bash_profile
2、下载国内的安装脚本:
git clone https://gitee.com/jinxin.70/install.git
cd install
我已经将脚本install.sh中的BREW_REPO变量改过了,有兴趣你可以打开脚本看看
BREW_REPO="https://github.com/Homebrew/brew"
改成了
BREW_REPO="https://gitee.com/mirrors/homebrew.git"
3、接着,运行 install.sh 以安装 Homebrew:
此时,你可能会卡在
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
ctrl+c停下,继续下一步
4、手动克隆core和cask
cd /usr/local/Homebrew/Library/Taps/homebrew
git clone https://gitee.com/jinxin.70/homebrew-core.git
git clone https://gitee.com/jinxin.70/homebrew-cask.git
5、然后继续运行安装脚本install.sh
bash ~/install/install.sh
6、安装好后,替换核心包仓库的配置为阿里云镜像
# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 应用生效
brew update
参考:
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
https://developer.aliyun.com/mirror/homebrew
https://juejin.cn/post/6844903782589923335