安装 node.js 后我执行以下命令:
sudo apt-get install npm
并出现错误:
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 upgrade -f npm node-gyp
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... 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:
nodejs-dev : Depends: libssl-dev (>= 1.0.0g) but it is not going to be installed
E: Broken packages
答案1
在经历了无数错误之后,终于成功解决问题。以下是我遵循的步骤。
首先我按照以下步骤安装“curl”http://sourcedigit.com/20782-install-curl-ubuntu-via-command-line/。本文提供了两种安装 curl 的方法,我使用以下方法成功安装了 curl“安装 Curl 的另一种方法”。
然后我按顺序执行命令
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs
通过执行上述 nodejs 命令,node js 版本 8 与 npm 版本 5.3.0 一起安装
答案2
为此添加 python 库:
sudo apt-get install python-software-properties
使用以下命令添加最新 nodejs 的 ppa:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
然后尝试:
sudo apt install -y nodejs
我希望这对你有用,因为这对我有用。