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

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

相关推荐
Dumbness15 小时前
毕设后台导出 CSV 的 4 个坑:date 字段漏了公式防护,搜索框输入 % 能扫全表
node.js·express
todoitbo16 小时前
我在 Mac 上用 Docker 部署 Nexent:从拉取镜像到接入模型
macos·docker·大模型·ai智能体·nexent·快速入门与环境准备
独隅17 小时前
WebStorm macOS 安装部署与高效调优实战指南
ide·macos·webstorm
fthux1 天前
Tick Rest,一个休息提醒工具的自我修养
macos·开源·swift
FPGA小迷弟2 天前
FPGA 与千兆以太网:各类物理接口的形式、区别、使用方法与应用场景详解
tcp/ip·macos·fpga开发·udp·fpga
longzhizhui9262 天前
Ubuntu 全版本 CVE-2026-98432 内核安全升级操作手册
ubuntu·网络安全·云计算·bash
wno7043 天前
node.js中使用jquery
前端·node.js·jquery
damoluomu3 天前
Node 的 Headless 出厂没有前台,Java 的 Headless 是从门户里长出来的
java·开发语言·node.js
Dumbness3 天前
一个手机号验证码登录接口的五个坑:无限发码、无限试码,传个数字就让 Express 进程退出
node.js·express