节点软件包管理器以某种方式损坏,现在无法安装

扎克·库克(Zach Cook)

今天,当我决定npm update -g在nodejs应用程序目录中使用时遇到了一个问题这是一个错误的决定,因为它使我遇到了npm常见而灾难性的问题

解决方案是重新安装nodejs和npm。不幸的是,当我使用sudo apt-get install npm安装npm时不起作用。

终端中的完整错误在这里:

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

如何正确安装npm并再次运行?

谢谢。

卡雷尔

更新

关于此答案下方的William Entriken的评论,有一种更好的方法可以在Ubuntu上以本机软件包形式安装Node.js。

在当前所有受支持的Ubuntu版本中,Node.js均作为快照包提供。特定于Node.js的开发人员可以从一个或多个当前受支持的版本中进行选择,并直接从NodeSource获得定期的自动更新。Node.js版本6、8、9、10、11、13和14当前可用,并且Snap Store在Node.js版本发布后的数小时或数分钟内进行了更新。

可以使用单个命令来安装节点,例如:

sudo snap install node --classic --channel 9/stable 

可以通过以下命令访问节点快照node,例如:

$ node -v   
v9.9.0

作为节点快照的一部分,将安装npm的最新版本。npm应该在常规外壳中的节点repl外部运行。安装节点快照后,运行以下命令以启用npm更新检查:

须藤chown -R $ USER:$ {id -gn $ USER)/ home /您的用户名/.config

your-username用您自己的用户名替换上述命令。然后运行npm -v以检查npm的版本是否为最新。例如,我检查npm是最新的,使用命令检查已经安装的名为yarn的软件包的版本,npm list yarn然后使用命令将现有的yarn软件包更新为最新版本。npm update yarn

用户可以随时在Node.js版本之间切换,而无需使用其他工具,例如nvm(节点版本管理器),例如:

sudo snap refresh node --channel=8/stable

用户可以通过以下方式测试可以从最新边缘通道安装的最新版本的Node.js:该边缘通道当前正在跟踪Node.js版本12:

sudo snap switch node --edge

仅建议那些愿意参与上游测试和错误报告的用户使用此方法。


原始答案

要在所有当前受支持的Ubuntu版本中安装最新的LTS版本的Node.js(nodejs)和用于Node.js的程序包管理器(npm),请打开终端并运行以下命令:

sudo apt-get remove nodejs npm ## remove existing nodejs and npm packages
sudo apt-get install curl  
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs  

如果要复制这三个命令,请不要在第二个命令的末尾忽略连字符。

nodejs软件包包含以及nodejs二进制文件npm,因此您无需npm单独安装但是,为了使某些npm软件包(例如那些需要从源代码构建的软件包)起作用,您将需要安装该build-essential软件包:

sudo apt-get install build-essential  

LTS计划

master每六个月就会减少Node.js的主要新版本新的偶数版本(例如v6,v8,v10等)在4月被削减。新的奇数版本(例如v5,v7,v9)在10月被削减。

剪切新的奇数主版本后,以前的偶数主版本将过渡到“长期支持”计划。

LTS计划涵盖的每个主要版本将从进入LTS覆盖之日起有效维护18个月。在这18个月的积极支持之后,主要版本将过渡到“维护”模式另外12个月。

非LTS安装

当前到2017年3月,用于安装最新的非LTS版本的Node.js(发布时为v8)的命令如下:

sudo apt-get remove nodejs npm ## remove existing nodejs and npm packages
sudo apt-get install curl  
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs  

Node.js LTS时间表

发布LTS状态代号LTS开始维护开始维护结束
6.x活性硼2016-10-18 2018年4月2019年4月
7.x否LTS               
8.x活性碳2017-10-31 2019年4月2019年12月
9.x否LTS               
10。 x Active Dubnium 2018年10月2020年4月2021年4月  
11.x No LTS 2019-04-01 2019-06-30 
12.x 2019-10-22 2021-04-01 2022-04-01 
13.x No LTS 2020-04 -20 2020-06-01 
14.x当前的m 2020-10-20 2021-10-20 2023-04-30

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法在Ubuntu中使用节点软件包管理器安装软件包

无法在命令行或Synaptic软件包管理器中安装软件包

Synaptic软件包管理器:无法应用更改!首先修复损坏的程序包。

如何以最正确的方式在openSUSE Tumbleweed上安装Conan软件包管理器?

在terramaster NAS上安装软件包管理器

查找软件包管理器未安装的文件

Swift软件包管理器无法编译通过Homebrew安装的ncurses

无法从Synaptic软件包管理器安装unity-tweak-tool

无法在Visual Studio 2015中安装Nuget软件包管理器

无法从Nuget软件包管理器安装Microsoft.EntityFrameworkCore

无法在新安装的Ubuntu 16.04 LTS上更改我的软件包管理器

安装get deb后无法打开synaptic软件包管理器

NuGet软件包管理器窗口无法打开

AIX的软件包管理器

Busybox的软件包管理器

如何通过软件包管理器安装Swift软件包?

Xubuntu 14.04使用Synaptic软件包管理器删除“未安装”的软件包

Cygwin软件包管理器-未显示已安装的软件包

Debian:使软件包管理器了解手动安装的软件包

所有Debian软件包管理器由于Python错误而损坏

从Windows上的Weka软件包管理器安装后,无法在weka 3.7.10中使用libsvm

在没有软件包管理器的情况下安装软件

Skype安装失败。如何从Ubuntu的软件包管理器安装Skype?

在华硕路由器上安装软件包管理器

如何离线安装Atom软件包或当原子软件包管理器不工作时如何安装?

损坏的包管理器

如何使用软件包管理器工具从存储库在centos 8中安装sshfs

linux软件包管理器安装的库是静态链接还是动态链接?

如何在基于Java的Docker映像中安装软件包管理器