无法在 Ubuntu 上将 npm 更新到最新版本

use*_*939 5 terminal updates apt npm

首先,我安装 npm

sudo apt-get install -y npm
Run Code Online (Sandbox Code Playgroud)

其中安装了 npm 版本 3.5.2。然后我尝试将其更新到最新版本,但失败了。无法为此找到合适的解决方案。

sudo npm install npm@latest -g
? ?????????????????????????????????????????????????????????????????????????????
WARN engine npm@7.5.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine npm@7.5.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":/usr/local/lib
??? (empty)

npm ERR! Linux 4.15.0-135-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "npm@latest" "-g"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552' -> '/usr/local/lib/node_modules/npm/node_modules/@npmcli/ci-detect'
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@npmcli/ci-detect-c7bf9552' -> '/usr/local/lib/node_modules/npm/node_modules/@npmcli/ci-detect'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /home/some/path/npm-debug.log
npm ERR! code 1
Run Code Online (Sandbox Code Playgroud)

小智 6

我遇到了完全相同的问题,经过一番研究后我发现了这篇文章。本文给出了几个选项,带有 nvm 安装的选项 1 对我有用。

sudo apt update

sudo apt install build-essential checkinstall libssl-dev

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.1/install.sh | bash

nvm --version

nvm ls-remote

nvm install [version.number]
Run Code Online (Sandbox Code Playgroud)

这篇文章中的更多信息: https ://phoenixnap.com/kb/update-node-js-version

  • 第三条命令后重新启动终端! (3认同)

小智 5

这是一个结果:https : //github.com/npm/cli/issues/2599

如果您对使用 npm 版本 6(当前 lts)感到满意,那么您可以运行:

sudo npm install -g npm@latest-6

要安装最新的版本 6,这可以节省您涉及另一个包管理器。