在Ubuntu 16.04上安装npm的问题

时间:2016-12-01 09:50:53

标签: javascript node.js linux ubuntu npm

尝试使用简单的sudo apt-get install npm在Ubuntu 16.04上安装npm时出现以下错误:

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 (>= 0.3.0-2) but it is not going to be installed
       Depends: node-ansi-color-table 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 (>= 3.0.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-underscore 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.

我检查了是否安装了节点:

$ which nodejs
/usr/bin/nodejs
$ which node
/usr/bin/node

从这里,我有点失落。有谁知道从这里做什么?

3 个答案:

答案 0 :(得分:0)

我建议您重新安装Nodejs

  

npm:取决于:nodejs但不会安装

错误中的

表示未安装nodejs(未正确安装)。

我建议您从https://nodejs.org/en/download/下载源代码 node-v6.9.1.tar.gz

然后

tar -zxvf  node-v6.9.1.tar.gz

cd node-v6.9.1

./configure

make

sudo make install
将通过上述步骤在您的计算机上安装

Nodejs NPM

您可以在命令提示符下使用node -vnpm -v验证安装。

答案 1 :(得分:0)

最后我通过installing nvm解决了问题(将版本号调整为当前版本):

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"  # OR LOG OUT AND BACK IN AGAIN

然后我使用nvm安装最新版本的节点,它也安装了npm。

nvm install node

我希望这可以帮助其他人解决同样的问题。

答案 2 :(得分:0)

请参阅Node Package Manager got corrupted

您可以执行以下操作

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  

这适用于我的Ubuntu 16.04.2