当我尝试用sudo npm install -g npm更新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。
发布于 2021-02-28 20:13:30
在过去的两天里,我遇到了同样的问题,但是,我设法找到了解决方案。
首先,您需要安装nvm。您可以在此处找到并下载最新版本:nvm for windows
选择nvm-setup.zip,然后继续并按照安装过程进行操作。
之后,打开你的windows终端,然后尝试输入nvm -v,看看它是否安装成功并安装了最新版本。
然后,如果一切正常,则键入nvm install node。
这会将您的节点更新到最新的可用版本。
发布于 2021-06-08 02:02:07
使用sudo /usr/bin/npm install -g npm更新npm...这将使用使用Ubuntu的包管理器安装的旧版本的npm进行引导。
如果您安装了npm或nodejs的多个版本,请在启动时始终使用完整路径,否则在运行时可能会出现错误。
https://stackoverflow.com/questions/66158892
复制相似问题