【问题标题】:EACCES Issue on npm fresh install on WSL Debian trying to update to the latest versionWSL Debian 上的 npm 全新安装上的 EACCES 问题尝试更新到最新版本
【发布时间】:2019-05-29 22:33:21
【问题描述】:

大家好,我从 Debian 的新 wsl 发行版开始,并在上面安装了 nodejs 和 npm。

当尝试使用以下命令更新到最新版本的 npm 时:

sudo npm install npm@latest -g

从我在互联网上看到的研究中,我遇到了一些在 wsl 上似乎很常见的奇怪问题,唯一似乎有效但没有真正正确解决的答案是使用以下命令将不安全权限设置为 true:

npm config set unsafe-perm true

我会避免使用这种方法并找到更干净的方法来解决问题。

这是控制台输出:

####@#####:~$ sudo npm install npm@latest -g
npm ERR! path /usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/wrap- 
ansi
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename
npm ERR! Error: EACCES: permission denied, rename 
'/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/wrap-ansi' -> 
'/usr/lib/node_modules/.staging/wrap-ansi-9f8997e7'
npm ERR!  { [Error: EACCES: permission denied, rename 
'/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/wrap-ansi' -> 
'/usr/lib/node_modules/.staging/wrap-ansi-9f8997e7']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, rename 
'/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/wrap-ansi' -> 
'/usr/lib/node_modules/.staging/wrap-ansi-9f8997e7'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'rename',
npm ERR!      path:
npm ERR!       '/usr/lib/node_modules/.staging/npm- 
18aca6f9/node_modules/wrap-ansi',
npm ERR!      dest: '/usr/lib/node_modules/.staging/wrap-ansi-9f8997e7' },
npm ERR!   stack:
npm ERR!    "Error: EACCES: permission denied, rename 
'/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/wrap-ansi' -> 
'/usr/lib/node_modules/.staging/wrap-ansi-9f8997e7'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path:
npm ERR!    '/usr/lib/node_modules/.staging/npm-18aca6f9/node_modules/wrap- 
ansi',
npm ERR!   dest: '/usr/lib/node_modules/.staging/wrap-ansi-9f8997e7' }
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 (though this is not 
recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-03-15T23_53_32_851Z-debug.log

我按照 nodejs 网站的文档在 root 模式下使用 curl 进行安装,以获取 node 的最新 11.x 版本的存储库。

提前致谢!

【问题讨论】:

  • 在我的 WSL 中我也很讨厌这一点,所有全局安装都突然失败。设置 npm config set unsafe-perm true 对我不起作用。
  • 您好,实际上我只在全局安装 npm 包以供其他人全局安装时遇到问题,我没有任何问题可能要注意在您的主文件夹也许 npm 文档中的这个链接也可以帮助你:docs.npmjs.com/…
  • 谢谢。前几天我试过了,没有运气。切换到yarn,它可以正常工作,所以我不会抱怨。有时你只是打破 npm 而你不知道为什么,哈哈。

标签: node.js npm


【解决方案1】:

在 WSL Ubuntu 发行版上遇到此问题,并且仅在 rename 上。

即使在我的 node_modules 目录中使用 chown 之后,npm update 也会发生。

我得到的解决方法是简单地避免update 并改用install(npm install npm@x 在技术上也是一个更新)。我知道这很麻烦,但除此之外我不知道如何让它工作。 重命名目录的命令会触发此操作,但不会在 createdelete 上触发。

【讨论】:

  • 这对我不起作用,因为有些项目有安装后操作将使用rename ...
  • @charlybones 可能会尝试升级到 WSL 2,显然那里有更好的文件 IO 管理。在此之后我回到 mac 时,我自己没有给自己机会。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 2014-06-13
  • 2015-11-12
  • 2014-12-04
相关资源
最近更新 更多