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

1. 检查网络连接

确保你的网络可以正常访问 ghcr.io 和 github.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

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

相关推荐
风尘小子5 天前
node.js系列:process配置
前端·node.js
怕浪猫5 天前
ZCode 开源了来看看这是个什么东西
node.js·github·代码规范
flash俊杰5 天前
Electron 打包后窗口 30 秒不出现:一个 ABI 不匹配的血案
electron·node.js
@tangguo1235 天前
npm 和 yarn 配置说明
前端·javascript·npm·node.js·yarn
flash俊杰6 天前
一套代码接入所有大模型:OpenAI 兼容适配器设计
node.js·openai
右耳朵猫AI6 天前
Node.js周刊2026W38 | 进程中断缺陷修复、Copilot 迁至 Rust、Node 新增 VFS
javascript·后端·node.js
黑化旺仔6 天前
【OC】KVO
macos·ios·objective-c·cocoa
光影少年6 天前
Express 中间件原理
后端·node.js·express
时速GEO系统6 天前
初元 AI V1.1 版本升级,首个正式版发布一周・实现生成、部署、上线、优化全流程自动化闭环
人工智能·数据挖掘·node.js