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

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

相关推荐
萌萌哒草头将军1 小时前
Node.js v24.6.0 新功能速览 🚀🚀🚀
前端·javascript·node.js
Cosmoshhhyyy1 小时前
linux远程部署dify和mac本地部署dify
linux·运维·macos
行星0081 小时前
mac 通过homebrew 安装和使用nvm
macos·npm·node.js
kngines8 小时前
【Node.js从 0 到 1:入门实战与项目驱动】1.3 Node.js 的应用场景(附案例与代码实现)
node.js
2501_928094659 小时前
Mac电脑录屏工具 Omi录屏专家(Mac中文)
macos·mac·录屏工具·omi
森之鸟12 小时前
Mac chrome浏览器下载DevEco Studio 6.0.0 Beta2失败
前端·chrome·macos
FairGuard手游加固20 小时前
版本更新!FairGuard-Mac加固工具已上线!
macos
xrkhy1 天前
nvm安装详细教程(卸载旧的nodejs,安装nvm、node、npm、cnpm、yarn及环境变量配置)
前端·npm·node.js
金玉满堂@bj1 天前
OS设备UDID查看方法
macos·objective-c·cocoa