电脑系统与虚拟机系统 · 2022年6月2日 0

npm安装时报错 E: Unable to correct problems, you have held broken packages.

在安装npm时报出一下错误:

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

在此过程中尝试了大部分操作基本无用,最后确认可能时缺少环境。
执行一下代码可解决该问题:
sudo apt-get install nodejs-dev node-gyp libssl1.0-dev
执行过程中会需要确认点击Y即可。完成后执行npm的安装工作。
执行npm -v 即可查看成功安装的版本。