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

深入解析:mac电脑安装 nvm 报错如何解决

深入解析: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 directory
0.0%curl: (23
) Failure writing output to destination
download 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 directory
0.0%curl: (23
) Failure writing output to destination
download 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.wooajung.com/news/35399.html

相关文章:

  • 洛谷 P12078 [OOI 2025] Best Runner 题解
  • 远程git ssh配置1
  • 7月24日总结
  • VIRTUBOX BUG
  • 精通Python PDF裁剪:从入门到专业的三重境界
  • 如何在群晖虚拟机快速部署线上web网站并实现公网访问
  • 向他人分享我的音频
  • - BigBosscyb - 博客园
  • 整体二分
  • 闲来无事
  • - daydreamer_zcxnb - 博客园
  • - Redamancy_Lydic - 博客园
  • - darling331 - 博客园
  • - kintsgi - 博客园
  • TIM外部中断
  • LPC总线设计及其仿真验证
  • Fluent许可证类型
  • 多值依赖
  • Windows 验证耳机输入是否正常
  • ABC典题总结
  • springboot项目解决报错:spring boot application in default package
  • LaTeX中为何推荐substack而不使用\atop?
  • 手机网页版浏览器seo案例分析及解析
  • 知名品牌vi设计宁波优化推广找哪家
  • 做国际贸易的网站沧州网站推广优化
  • 网站框架都有什么用重庆网站快速排名提升
  • 凡科自助建站靠谱吗网站安全检测在线
  • 哪些国家网站无须备案企业所得税优惠政策
  • 泰安房产网信息网官网seo服务 收费
  • ps怎样做网站详情页建立免费个人网站