当前位置: 首页 > web >正文

mac电脑安装 nvm 报错如何解决

前言

已知:安装nvm成功;终端输入nvm -v 有版本返回

1. 启动全局配置环境变量失败

source ~/.zshrc~ 

返回:

source: no such file or directory: /Users/你的用户名/.zshrc~

2 安装node失败

nvm install 16.13

返回:

mkdir: /Users/你的用户名/.nvm/alias: Permission denied
mkdir: /Users/你的用户名/.nvm/alias: Permission denied
Downloading and installing node v16.13.2...
mkdir: /Users/你的用户名/.nvm/.cache: Permission denied
creating directory /Users/你的用户名/.nvm/.cache/bin/node-v16.13.2-darwin-arm64/files failed
Downloading https://nodejs.org/dist/v16.13.2/node-v16.13.2-darwin-arm64.tar.xz...
Warning: Failed to create the file                                             
Warning: /Users/你的用户名/.nvm/.cache/bin/node-v16.13.2-darwin-arm64/node-v16.13.
Warning: 2-darwin-arm64.tar.xz: No such file or directory0.0%curl: (23) Failure writing output to destinationdownload from https://nodejs.org/dist/v16.13.2/node-v16.13.2-darwin-arm64.tar.xz failed
grep: /Users/你的用户名/.nvm/.cache/bin/node-v16.13.2-darwin-arm64/node-v16.13.2-darwin-arm64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Detected that you have 8 CPU core(s)
Running with 7 threads to speed up the build
Clang v3.5+ detected! CC or CXX not specified, will use Clang as C/C++ compiler!
mkdir: /Users/你的用户名/.nvm/.cache: Permission denied
creating directory /Users/你的用户名/.nvm/.cache/src/node-v16.13.2/files failed
Downloading https://nodejs.org/dist/v16.13.2/node-v16.13.2.tar.xz...
Warning: Failed to create the file                                             
Warning: /Users/你的用户名/.nvm/.cache/src/node-v16.13.2/node-v16.13.2.tar.xz: No 
Warning: such file or directory0.0%curl: (23) Failure writing output to destinationdownload from https://nodejs.org/dist/v16.13.2/node-v16.13.2.tar.xz failed
grep: /Users/你的用户名/.nvm/.cache/src/node-v16.13.2/node-v16.13.2.tar.xz: No such file or directory
Provided file to checksum does not exist.

3 查看全局变量,没有看到配置好的nvm配置

echo $PATH  

解决

结合以上三个问题都是因为安装nvm时,没有安装好!还有权限问题。

1 修复目录权限

sudo chown -R $(whoami) ~/.nvm

2 重新安装nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

3 查看当前电脑的shell配置

echo $SHELL

可能输出是/bin/bash或者/bin/zsh

4 修改配置文件

打开配置文件

nano ~/.zshrc  # 或 nano ~/.bash_profile

在文件末尾添加

 export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # 加载 nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # 加载自动补全

5 重新启动配置文件

如果是bin/zsh,使用下面的命令:

source ~/.zshrc  

如果是/bin/bash,使用下面的命令:

 source ~/.bash_profile

6 验证nvm 和npm是否可以使用

nvm install #指定版本
nvm ls #看目前存在的版本
nvm --version  # 应显示 NVM 版本
node -v        # 应显示 Node.js 版本
npm -v         # 应显示 npm 版本
which node     # 应显示 ~/.nvm/versions/node/.../bin/node
which npm      # 应显示 ~/.nvm/versions/node/.../bin/npm

补充说明

打开/.zshrc 文件后,如何保存修改呢?

按 Ctrl + X后请添加图片描述按Y确认保存,最后按Enter键保存。

http://www.xdnf.cn/news/10614.html

相关文章:

  • 【华为云Astro Zero】组装设备管理页面开发(图形拖拽 + 脚本绑定)
  • 【更正补全】edu教育申请通过方案
  • vLLM实战部署embedding、reranker、senseVoice、qwen2.5、qwen3模型
  • STM32G4 电机外设篇(四)DAC输出电流波形 + CAN通讯
  • mybatis03
  • neo4j 5.19.0两种基于向量进行相似度查询的方式
  • new语法
  • TDengine 高级功能——读缓存
  • R语言基础| 创建数据集
  • 常见 Web 安全问题
  • MySQL数据库从0到1
  • Java设计模式之备忘录模式详解
  • 第九章:LLMOps自动化流水线:释放CI/CD/CT的真正力量
  • OpenRouter使用指南
  • Git-flow流
  • react实现markdown文件预览
  • 关于海洋数据上云的一些机遇与挑战
  • python中if __name__ == ‘__main__‘ 的作用再谈
  • ffmpeg 的视频格式转换 c# win10
  • 【C语言】C语言经典小游戏:贪吃蛇(下)
  • DAY41 CNN
  • 15.MQTT协议和云平台(ESP8266)
  • Codeforces Round 1028 (Div. 2)(A-D)
  • SystemVerilog—new函数的使用和误区
  • 聚类分析 | MATLAB实现基于SOM自组织特征映射聚类可视化
  • Spring AI 之检索增强生成(Retrieval Augmented Generation)
  • 一步一步配置 Ubuntu Server 的 NodeJS 服务器详细实录——3. 服务器软件更新,以及常用软件安装
  • 面向连接的运输:TCP
  • 百度蜘蛛池的作用是什么?技术@baidutopseo
  • 【算法设计与分析】实验——二维0-1背包问题(算法分析题:算法思路),独立任务最优调度问题(算法实现题:实验过程,描述,小结)