36

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.
  • 2
    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 ) – Peter Krauss Dec 12 '15 at 20:01
34

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.

  • 7
    How would he run "npm -v" if he cannot install npm...? – Mariano Argañaraz Nov 30 '15 at 17:56
  • 10
    The "modern" apt-get install nodejs do also npm updated installation, so, I understand that apt-get install npm must be avoided (!). – Peter Krauss Dec 12 '15 at 19:58
  • 1
    See stackoverflow.com/a/34244847/287948 – Peter Krauss Dec 12 '15 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 '18 at 1:01
7

Try installing NodeJs like this:

sudo apt-get install nodejs

Since NodeJs installs node and npm

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

  • 4
    He cannot install npm men, how could he get to point 3?! – Mariano Argañaraz Nov 30 '15 at 17:56
0

Problem is registry, execute this command,

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

I work on this way, check it work for you

  • 4
    How would he run "npm config..." if he cannot install npm...? – Mariano Argañaraz Nov 30 '15 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. – Jay Patel Dec 1 '15 at 4:12
0

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

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

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.

-2

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

sudo apt-get remove nodejs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.