node.js - 'sudo npm install -g npm' 失败
问题描述
当我尝试通过 更新 npm 时sudo npm install -g npm
,Ubuntu 给了我错误
操作系统版本是 Ubuntu,运行在 WSL 下Version 20H2 (OS build 19042.746)
,我在老版本的 Win10 中没有遇到过这个问题。
root@DESKTOP-D03G7FK:~# sudo npm update npm -g
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/yargs-parser
npm ERR! dest /usr/lib/node_modules/.staging/yargs-parser-b095ed45
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/yargs-parser' -> '/usr/lib/node_modules/.staging/yargs-parser-b095ed45'
npm ERR! [OperationalError: EACCES: permission denied, rename '/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/yargs-parser' -> '/usr/lib/node_modules/.staging/yargs-parser-b095ed45'] {
npm ERR! cause: [Error: EACCES: permission denied, rename '/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/yargs-parser' -> '/usr/lib/node_modules/.staging/yargs-parser-b095ed45'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/yargs-parser',
npm ERR! dest: '/usr/lib/node_modules/.staging/yargs-parser-b095ed45'
npm ERR! },
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/yargs-parser',
npm ERR! dest: '/usr/lib/node_modules/.staging/yargs-parser-b095ed45'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-02-12T12_53_38_994Z-debug.log
问题还没有解决,我切换到WSL2,因为WSL有Linux内核,所有问题都解决了,我认为是WSL的bug。
解决方案
在过去的 2 天里,我遇到了同样的问题,但唉,我设法找到了解决方案。
首先,您需要安装nvm
. 您可以在此处找到最新版本并下载:nvm for windows
选择nvm-setup.zip
然后继续并按照安装过程进行操作。
之后打开您的 Windows 终端,然后尝试输入nvm -v
以查看它是否成功安装并具有最新版本。
然后,如果一切正常,请键入nvm install node
。
这会将您的节点更新到最新的可用版本。
推荐阅读
- c# - 将文本作为 guid 插入二进制 (16)
- html - 如何在 angular5/angularitics 中安装单独的 mixpanel 项目以进行开发和生产
- html - 输入类型文本为带斜线的格式化日期
- css - 媒体查询功能中从地图生成 SASS 动态颜色
- android - 如何在 google play 上检查另一个 android 应用程序的许可证有效性
- html - XSLT 如果条件抛出 - 缺少必需的属性“测试”
- python - 如何从python中的数组中删除分号?
- java - java scheduleWithFixedDelay 内存泄漏
- modal-dialog - Vue.js 2:模式对话框 - 方法成功时关闭
- mysql - Mysql查找所有用户的共同值