无法更新 npm?

Posted

技术标签:

【中文标题】无法更新 npm?【英文标题】:Unable to update npm? 【发布时间】:2018-11-30 20:42:36 【问题描述】:

当我尝试为某些工作更新 NPM 时,此错误一直发生在我身上。我以前在 Windows 命令提示符 中一直使用它,但在 Linux Bash

中没有

npm i -g npm

Specify configs in the ini-formatted file:
/root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@5.6.0 /usr/lib/node_modules/npm
root@DESKTOP-SJPLLRG:~# npm -v
5.6.0
root@DESKTOP-SJPLLRG:~# npm i -g npm
npm ERR! path /usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/stream-each
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename
npm ERR! Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/stream-each' -> '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/.stream-each.DELETE'
npm ERR!   Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/stream-each' -> '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/.stream-each.DELETE'
npm ERR!   cause:
npm ERR!     Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/stream-each' -> '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/.stream-each.DELETE'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'rename',
npm ERR!      path: '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/stream-each',
npm ERR!      dest: '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/.stream-each.DELETE' ,
npm ERR!   stack: 'Error: EACCES: permission denied, rename \'/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/stream-each\' -> \'/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/.stream-each.DELETE\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/stream-each',
npm ERR!   dest: '/usr/lib/node_modules/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/mississippi/node_modules/.stream-each.DELETE',
npm ERR!   parent: 'mississippi' 
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-06-21T13_00_43_617Z-debug.log

关于我的环境的一些细节:

1) 我使用 Windows Subsystem for Linux Platform 安装 Node.js

2) 我只在 root 中尝试过。

3) 我尝试使用NPM update Link中显示的一些命令更新 NPM 包

但仍然无法执行更新。它显示以下错误

root@DESKTOP-SJPLLRG:~# npm install npm -g
-bash: /usr/bin/npm: No such file or directory
root@DESKTOP-SJPLLRG:~#

我什至无法继续前进。有什么办法可以清除这个错误并更新 NPM 吗?

编辑2:

我尝试重新安装 Node.js 和 NpM,但弹出以下错误

ash@DESKTOP-SJPLLRG:~$ sudo apt-get install npm
[sudo] password for ash:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 npm : Depends: nodejs but it is not going to be installed
       Depends: node-abbrev (>= 1.0.4) but it is not going to be installed
       Depends: node-ansi (>= 0.3.0-2) but it is not going to be installed
       Depends: node-ansi-color-table but it is not going to be installed
       Depends: node-archy but it is not going to be installed
       Depends: node-block-stream but it is not going to be installed
       Depends: node-fstream (>= 0.1.22) but it is not going to be installed
       Depends: node-fstream-ignore but it is not going to be installed
       Depends: node-github-url-from-git but it is not going to be installed
       Depends: node-glob (>= 3.1.21) but it is not going to be installed
       Depends: node-graceful-fs (>= 2.0.0) but it is not going to be installed
       Depends: node-inherits but it is not going to be installed
       Depends: node-ini (>= 1.1.0) but it is not going to be installed
       Depends: node-lockfile but it is not going to be installed
       Depends: node-lru-cache (>= 2.3.0) but it is not going to be installed
       Depends: node-minimatch (>= 0.2.11) but it is not going to be installed
       Depends: node-mkdirp (>= 0.3.3) but it is not going to be installed
       Depends: node-gyp (>= 0.10.9) but it is not going to be installed
       Depends: node-nopt (>= 3.0.1) but it is not going to be installed
       Depends: node-npmlog but it is not going to be installed
       Depends: node-once but it is not going to be installed
       Depends: node-osenv but it is not going to be installed
       Depends: node-read but it is not going to be installed
       Depends: node-read-package-json (>= 1.1.0) but it is not going to be installed
       Depends: node-request (>= 2.25.0) but it is not going to be installed
       Depends: node-retry but it is not going to be installed
       Depends: node-rimraf (>= 2.2.2) but it is not going to be installed
       Depends: node-semver (>= 2.1.0) but it is not going to be installed
       Depends: node-sha but it is not going to be installed
       Depends: node-slide but it is not going to be installed
       Depends: node-tar (>= 0.1.18) but it is not going to be installed
       Depends: node-underscore but it is not going to be installed
       Depends: node-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

你们能给我提供任何重新安装 Node.js 和 NPM 的技术吗?

【问题讨论】:

你试过运行sudo npm install npm -g吗? @PrashantBaid 我是 sudo 模式。我尝试使用仅提到的上述命令进行更新。还是不行。 【参考方案1】:

命令输出为:

-bash: /usr/bin/npm: No such file or directory

由于某种原因,您的系统中似乎不存在 npm。 尝试重新安装 NodeJS。

【讨论】:

【参考方案2】:

你需要清理 npm 的缓存sudo npm cache clean -f

然后,更新命令npm install -g npm

然后,删除易受攻击的

npm 审计修复 --force

【讨论】:

以上是关于无法更新 npm?的主要内容,如果未能解决你的问题,请参考以下文章

CSS 更新后 NPM 模块无法导入

无法使用 NPM 更新到最新的打字稿

docker 中的 npm 更新失败

由于以下错误,无法运行任何 npm 命令 - 错误:找不到模块“semver”

使用 Nodist 更新 NPM

我不能用 npm 更新电子