1. 检查网络连接
确保你的网络可以正常访问 ghcr.io 和 github.com:
ping ghcr.io
ping github.com
✅ 如果能收到回复,说明网络正常;
❌ 如果超时或无响应,可能是 网络代理/DNS问题。
2. 尝试替换 Homebrew 的下载镜像(使用国内源)
方法 1:使用中科大镜像
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
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"
然后重新运行:
brew install nvm
方法 2:使用清华镜像
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
然后重新运行:
brew install nvm
- 手动清除缓存并重试
rm -rf $(brew --cache)
brew cleanup
brew update
brew install nvm
- 如果仍然失败:手动安装 NVM(无需 Homebrew)
既然 Homebrew 安装困难,可以直接用 NVM 官方脚本安装:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
然后:
source ~/.zshrc # 或 source ~/.bashrc
nvm --version # 检查是否安装成功
🔍 常见问题排查
问题 解决方案
curl: (56) Recv failure 更换网络、使用代理、尝试国内镜像
portable-ruby 下载失败 手动下载并放入 $(brew --cache)
Homebrew 完全不能用 直接使用 NVM 官方脚本 安装 (推荐)
📌 最终推荐方案
如果 Homebrew 安装失败,直接使用 NVM 官方脚本安装(更简单):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.zshrc
nvm install node # 安装最新 Node.js
✅ 验证是否成功
nvm --version
node -v
npm -v
👉 如果都能正确输出版本号,说明成功!