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

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

相关推荐
亮子AI23 分钟前
【node.js】node.js 两种模块规范 CommonJS 和 ESM 如何选择?
node.js
孟祥_成都26 分钟前
nest.js / hono.js 一起学!日志功能/统一返回格式/错误处理
前端·node.js
亮子AI1 小时前
【node.js MySQL】node.js 如何连接 MySQL?
数据库·mysql·node.js
2501_927541091 小时前
Adobe Lightroom Classic 2025 Lrc图像处理工具Mac
图像处理·macos·adobe·lightroom·照片美化
2501_927541091 小时前
AlDente Pro Mac电脑充电限制保护工具
macos·电脑·电脑保护·电脑充电保护
Feibo20112 小时前
永远关闭mac更新
macos
weixin_462446232 小时前
pkg 手动下载依赖并解决打包时网络下载失败(Win / macOS)
macos·pkg
风为你而吹2 小时前
mac m3上使用vscode + esp-idf开发esp32
ide·vscode·macos
亮子AI2 小时前
【node.js】如何使用 node.js 来制作命令行应用?
node.js
七月shi人2 小时前
使用Node版本管理包n,在MAC电脑权限问题
前端·macos