尝试安装最新版本的 npm 但权限有问题

时间:2021-04-27 10:06:22

标签: node.js npm npm-install

我用 sudo 尝试并清理了缓存,但它仍然不起作用,请帮忙。谢谢!它说我没有权限以当前用户身份访问此文件,但谁有权限,我是唯一的用户

npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/string-width
npm ERR! dest /usr/local/lib/node_modules/.staging/string-width-fa87d55b
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/string-width' -> '/usr/local/lib/node_modules/.staging/string-width-fa87d55b'
npm ERR!  { [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/string-width' -> '/usr/local/lib/node_modules/.staging/string-width-fa87d55b']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/string-width' -> '/usr/local/lib/node_modules/.staging/string-width-fa87d55b'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'rename',
npm ERR!      path:
npm ERR!       '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/string-width',
npm ERR!      dest: '/usr/local/lib/node_modules/.staging/string-width-fa87d55b' },
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, rename \'/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/string-width\' -> \'/usr/local/lib/node_modules/.staging/string-width-fa87d55b\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path:
npm ERR!    '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/string-width',
npm ERR!   dest: '/usr/local/lib/node_modules/.staging/string-width-fa87d55b' }
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-04-27T09_59_20_887Z-debug.log

1 个答案:

答案 0 :(得分:0)

我有完全相同的问题。这不是文件权限。即使 chmod a+rwX -R ~/.nvm 也无济于事,以管理员身份运行终端也无济于事。我试过 npm i -g jest,效果很好