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.
3
  • 3
    I think nobody say, but apt-get install npm must be avoid (!). Check if npm -v is there before to try to install.... (read more below at @MarcoCerpi's answer ) Dec 12, 2015 at 20:01
  • Are you running a 32-bit system? If so, it is not officially supported and you need to use a build from the node unofficial-builds web site.
    – GregD
    May 10, 2020 at 17:52
  • Can't believe I'm still getting tripped over by this on Ubuntu 20.04...
    – Hank Chan
    Nov 29, 2020 at 7:28

9 Answers 9

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.

4
  • 8
    How would he run "npm -v" if he cannot install npm...? Nov 30, 2015 at 17:56
  • 12
    The "modern" apt-get install nodejs do also npm updated installation, so, I understand that apt-get install npm must be avoided (!). Dec 12, 2015 at 19:58
  • 1
    See stackoverflow.com/a/34244847/287948 Dec 12, 2015 at 21:09
  • I removed my PPA and I got ` npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed`
    – Jonathan
    May 25, 2018 at 1:01
7

Try installing NodeJs like this:

sudo apt-get install nodejs

Since NodeJs installs node and npm

2
  • 3
    doesn't work with 16.04
    – ZZ 5
    Jan 17, 2019 at 14:42
  • no npm installed with this...
    – Gigiux
    Jul 3, 2019 at 11:53
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

0
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

3
  • 4
    How would he run "npm config..." if he cannot install npm...? Nov 30, 2015 at 17:57
  • When he runs sudo apt-get install npm command its give "unmet dependencies error". I notice error npm already installed just need to set registry url. Dec 1, 2015 at 4:12
  • Also worked for me. Thank you!
    – Justech
    Feb 24, 2021 at 13:36
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

1
  • 4
    He cannot install npm men, how could he get to point 3?! Nov 30, 2015 at 17:56
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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .