我尝试安装 NodeJS v14 但破坏了所有内容,如何在不破坏依赖关系的情况下安装新版本?

我尝试安装 NodeJS v14 但破坏了所有内容,如何在不破坏依赖关系的情况下安装新版本?

因此,我发现出于某种原因,与 Windows 不同,您不能只选择 NodeJS 版本。当我正常安装时,我通过命令获得版本 10:

sudo apt-get install nodejs

在两台基于 Ubuntu 的机器上试过,一台是 Ubuntu 14(我知道是老版本),另一台是 Linux Mint 20.3 Una。两台机器都给我安装了 nodejs 10 版本,这个版本已经有好几年了。在 nodejs 网站上,我发现了这个帮助我打破系统的有用指南运行这个:

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

因此确实按照承诺安装了 nodejs 14,但现在无法安装任何依赖于 NodeJS 的东西。我得到了这样的 npm 错误,而 npm 对于使用 nodejs 来说非常必要:

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-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-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

我尝试删除 nodejs,但当我再次安装它时总是得到 v14,并且系统仍然崩溃。

您能帮我解决这个问题吗?您能解释一下我运行的命令的作用吗?

答案1

彻底删除 NodeJS(包、配置)

sudo apt purge nodejs
sudo apt autoremove
sudo apt purge npm

更新包列表

sudo apt update

注意:检查目录中是否有任何.npm或文件夹并将其删除。.nodehome

重新安装 NodeJS

sudo apt install nodejs

相关内容