Unable to install npm

#1

I get an error when I try to install npm due to which I can not install the few apps.
Error:

        apt-get install npm
        Reading package lists... Done
        Building dependency tree       
        Reading state information... Done
        Some packages could not be installed. This may mean that you have
        requested an impossible situation or if you are using the unstable
        distribution that some required packages have not yet been created
        or been moved out of Incoming.
        The following information may help to resolve the situation:
        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.

npm -v
3.10.10
nodejs -v
v6.12.0

I tried lot of solution on the internet to install but non of it has worked till now. Someone had a similar problem and tried to fix it?

#2

What happens when you do this?

sudo apt-get install -f
#3
sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

And same error as above while trying to install the npm.

#4

And what happen when you do this?

sudo apt-get remove nodejs npm
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nodejs npm

Your nodejs/npm packages are old.

#5

I am showing the last two commands. Update and upgrade are normal.

sudo apt-get remove nodejs npm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'npm' is not installed, so not removed
The following packages will be REMOVED:
  nodejs
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 44.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
[master b0fbdfe] saving uncommitted changes in /etc prior to apt run
 Author: root <root@localhost>
(Reading database ... 55409 files and directories currently installed.)
Removing nodejs (6.12.0-1nodesource1) ...
Processing triggers for man-db (2.7.0.2-5) ...
[master 1981638] committing changes in /etc after apt run
 Author: root <root@localhost>
 2 files changed, 2 deletions(-)
 delete mode 120000 alternatives/nodejs
 delete mode 120000 alternatives/nodejs.1.gz

and while installing npm:

sudo apt-get install nodejs npm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nodejs : Conflicts: npm
E: Unable to correct problems, you have held broken packages.

and I still the npm version:
npm -v
2.15.11

#6

Installing sudo apt-get install aptitude and then doing sudo aptitude install npm solves the problem.

Update: I was still having conflicting problem of node and nodejs, so symlink node to nodejs further solved the problem.
sudo ln -s /usr/bin/nodejs /usr/bin/node

#7

Thanks for solution
sudo apt-get remove nodejs npm
sudo apt-get update
sudo apt-get upgrade

After this command run these :-
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Now check…
node -v
npm -v

7 Likes
#8

thanks

1 Like
#9

@puranchand Thanks sooooo much this worked firs time!

1 Like
#10

I would like to ask you that how stable you find this build? I am also having similar issues. Any feedback in this regard would be helpful. Thanks.

#11

Installing an app on Yunohost will itself take care of the nodejs and npm. You don’t need to install it manually.

1 Like
#12

This worked for me, thanks!

#13

Work for me too ! Awesome, thanks !

1 Like
#14

Work for me too ! Awesome, thanks !

#15

Ah yes, I also faced this issue. Thanks for the pointers above. For future reference, the new versions of nodejs/npm are available if you need something else. Check out:

https://github.com/nodesource/distributions#installation-instructions