当前位置: 首页>>技术问答>>正文


无法在ubuntu上安装npm

, , ,

问题描述

试图在ubuntu 12.04上安装nodejs和npm。我用Google搜索并做到了。现在,我无法在机器上安装npm。

sudo apt-get install npm

这给了我这个

The following packages have unmet dependencies:
 npm : Depends: nodejs but it is not going to be installed
       Depends: nodejs-dev
       Depends: node-request but it is not going to be installed
       Depends: node-mkdirp but it is not going to be installed
       Depends: node-minimatch but it is not going to be installed
       Depends: node-semver but it is not going to be installed
       Depends: node-ini but it is not going to be installed
       Depends: node-graceful-fs but it is not going to be installed
       Depends: node-abbrev but it is not going to be installed
       Depends: node-nopt but it is not going to be installed
       Depends: node-fstream but it is not going to be installed
       Depends: node-rimraf but it is not going to be installed
       Depends: node-tar 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.

最佳解决方法

这看起来你可能安装了chris-lea node.js ppa,这很好。但是,你没有从那个ppa安装npm,因为它破坏了debian包的工作方式。相反,只需安装nodejs即可。安装完成后,运行npm -v,您应该会看到它已安装完毕。如果您没有使用chris-lea ppa更新您在Googled的网页上的问题,以了解如何在Ubuntu上安装nodejs。

次佳解决方法

尝试安装这样的NodeJ:

sudo apt-get install nodejs

由于NodeJ安装节点和npm

第三种解决方法

我按照this documentation解决了这个问题。

要记住使用npm的指针:

mkdir ~/nodejs/ && cd ~/nodejs
sudo apt-get install npm
npm install
npm update

在开发应用程序时,如果nodejs需要任何特定模块,则运行

cd ~/nodejs
npm install modulename   #for example sendgrid

有时,模块需要全局安装;然后用

sudo npm install modulename -g"

要删除模块:

cd ~/nodejs
npm uninstall modulename          # if locally installed or 
sudo npm uninstall modulename -g  # if globally installed

npm prune有助于删除未满足的依赖项

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/6731.html,未经允许,请勿转载。