mac安装nvm执行命令报错-解决方案

1. 检查网络连接

确保你的网络可以正常访问 ghcr.iogithub.com

bash 复制代码
ping ghcr.io
ping github.com

✅ 如果能收到回复,说明网络正常;

❌ 如果超时或无响应,可能是 网络代理/DNS问题。

2. 尝试替换 Homebrew 的下载镜像(使用国内源)

方法 1:使用中科大镜像

bash 复制代码
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"

然后重新运行:

bash 复制代码
brew install nvm

方法 2:使用清华镜像

bash 复制代码
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"

然后重新运行:

bash 复制代码
brew install nvm
  1. 手动清除缓存并重试
bash 复制代码
rm -rf $(brew --cache)
brew cleanup
brew update
brew install nvm
  1. 如果仍然失败:手动安装 NVM(无需 Homebrew)
    既然 Homebrew 安装困难,可以直接用 NVM 官方脚本安装:
bash 复制代码
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

然后:

bash 复制代码
source ~/.zshrc  # 或 source ~/.bashrc
nvm --version    # 检查是否安装成功

🔍 常见问题排查

问题 解决方案

curl: (56) Recv failure 更换网络、使用代理、尝试国内镜像

portable-ruby 下载失败 手动下载并放入 $(brew --cache)

Homebrew 完全不能用 直接使用 NVM 官方脚本 安装 (推荐)

📌 最终推荐方案

如果 Homebrew 安装失败,直接使用 NVM 官方脚本安装(更简单):

bash 复制代码
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.zshrc
nvm install node  # 安装最新 Node.js

✅ 验证是否成功

bash 复制代码
nvm --version
node -v
npm -v

👉 如果都能正确输出版本号,说明成功!

相关推荐
goodmao1 天前
【macOS】【mouse】设置鼠标大小
macos·计算机外设·鼠标·mouse
Magnum Lehar1 天前
macos信息采集器appledataharvester-3
macos·网络安全·系统安全
川川菜鸟1 天前
Claude Code 安装与配置完整指南(Mac)
macos
WarmSword1 天前
mac上用cursor/vscode调试root权限进程
c++·ide·vscode·macos·mac
Magnum Lehar1 天前
macos的信息采集器appledataHarvester-2
macos·网络安全·系统安全
echo-niuben1 天前
macOS 端已如何正常安装并配置XcodeBuildMCP ?
macos
刘某某.1 天前
Mac上缺失宋体字体,只有宋体-简
macos
Tom·Ge1 天前
在macOS上安装OpenClaw并实现Chrome网站自动化测试
chrome·macos·策略模式
Lo-Y-eH1 天前
Mac 安装 Ollama 部署 DeepSeek 模型
macos·ollama·deepseek·cherry studio
dingdingfish2 天前
GNU Parallel 学习 - 第1章:How to read this book
bash·shell·gnu·parallel