43

Tried to install nodejs and npm on ubuntu 12.04. I googled and did it. Now, I could not install npm on machine.

sudo apt-get install npm

Which gives me this

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.
Marco Ceppi
  • 48,827
user3297351
  • 549
  • 1
  • 4
  • 7

9 Answers9

40

This looks like you probably installed the chris-lea node.js ppa which is fine. However, you don't install npm from that ppa as it breaks the way debian packages work. Instead, just install nodejs. Once that's installed, run npm -v you should see it's now installed. If you didn't use the chris-lea ppa update your question on what webpage you Googled to find out how to install nodejs on Ubuntu.

Marco Ceppi
  • 48,827
7

Try installing NodeJs like this:

sudo apt-get install nodejs

Since NodeJs installs node and npm

4

Apt doesn't handle dependancy conflicts well, use snap or aptitude;

sudo aptitude install npm

I had to press "no" to the first solution it proposed, which did not include installing npm (that must be a bug in aptitude) then the second solution I pressed yes to hTHen check npm was installed:

npm --version

Jonathan
  • 3,984
1

I solved this issue by following this documentation.

Pointers to remember to work with npm:

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

While developing applications, if nodejs needs any particular module then run

cd ~/nodejs
npm install modulename   #for example sendgrid

Sometimes, modules needs to install globally; then use

sudo npm install modulename -g"

To remove a module:

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

npm prune helps to remove unmet dependencies

Zanna
  • 72,312
user3297351
  • 549
  • 1
  • 4
  • 7
1

Problem is registry, execute this command,

npm config set registry http://registry.npmjs.org/

I work on this way, check it work for you

Zanna
  • 72,312
1

First, you need to install the PPA in order to get access to its contents:

curl -sL https://deb.nodesource.com/setup_9.x | sudo bash -

(This for version 9, which is the latest version at the time of writing).

And then

sudo apt-get install nodejs
faizan
  • 111
0

Version conflict of manual installed npm and which comes with latest nodejs.

So you could try to remove nodejs, remove old npm and installed new nodejs again which comes with npm.

0

it worked in my case.

first-:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

then logout and come again and

 nvm install node

it will install npm . hope it will help

-2

Installing nodejs will install npm, so just remove nodejs then reinstall it:

sudo apt-get remove nodejs
Zanna
  • 72,312
Russo
  • 101