题主一开始按照官网(https://brew.sh/)提示的步骤操做:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
但第一句就失败了——由于非科学上网导致无法安装。因此选择安装中科大源。
顺序执行:
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
第三条指令可能会报错:
Error:
homebrew-core is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
but非科学上网时执行建议的git命令会超时。
解决方案:
cd /usr/local/Homebrew/Library/Taps/homebrew
rm -rf homebrew-core
cd ../
git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
然后在执行最开始报错的那条:
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
安装完成:
==> Next steps:
- 🎉 恭喜,安装成功!运行 `brew help` 开始体验吧
- 更多文档:
https://docs.brew.sh
https://brew.idayer.com
最后完成设置:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/' >> ~/.zprofile
source ~/.zprofile
参考资料:
https://brew.idayer.com/guide/change-source/
https://blog.csdn.net/qq_41576821/article/details/113830228