【发布时间】: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 而你不知道为什么,哈哈。