gpt4 book ai didi

node.js - WSL Debian 上的 npm 全新安装的 EACCES 问题尝试更新到最新版本

转载 作者:太空宇宙 更新时间:2023-11-03 22:57:53 24 4
gpt4 key购买 nike

大家好,我从 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进行安装,以获取最新11.x版本的node的存储库。

提前致谢!

最佳答案

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

即使在我的 node_modules 目录上使用 chown 后,npm update 也会发生这种情况。

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

关于node.js - WSL Debian 上的 npm 全新安装的 EACCES 问题尝试更新到最新版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55192170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com