Error on "update-alternatives" when installing/upgrading nodejs v0.10.30

So I get this error when doing apt-get upgrade

Setting up nodejs (0.10.30-1chl1~trusty1) ...
update-alternatives: error: alternative link /usr/bin/node is already managed by nodejs
dpkg: error processing package nodejs (--configure): subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing: nodejs
E: Sub-process /usr/bin/dpkg returned an error code (1)

NB: "nodejs --version" works, I get a clean "v0.10.30" but "node --version" doesn't since there is no link.

So far, I have tried:

  • complete removal of nodejs & new install
  • I manually removed the link /usr/bin/node to nodejs after removing nodejs, since it was still there and the issue is related to update-alternatives
  • using "update-alternatives --config nodesjs" (something was broken and repaired the first time I used it, but it didn't solve the issue. That error has not reappeared since).

I really encourage you to use nvm to install Node.js on your ubuntu machine (https://github.com/creationix/nvm). With that, the installation of any Node.js version becomes very easy.

Probably you have an older version of NodeJS installed and you get a conflict while upgrading.

The only package that uses /usr/bin/node is nodejs-legacy, so unless you have created that link by yourself or installed NodeJS from sources that's the package you need to remove:

$ sudo apt-get purge nodejs-legacy nodejs

After that just reinstall NodeJS, update and upgrade your software:

$ sudo apt-get install nodejs
$ sudo apt-get update && sudo apt-get upgrade

From the output you gave the NodeJS version from the PPA has priority over the other, so you should not have any problem installing it.

Other answers didn't resolved the problem on my setup, maybe because I was using the NodeSource repository instead of the official ones.

But I've simply removed all "alternatives" for the nodejs group first:

sudo update-alternatives --remove-all nodejs

And after that, a sudo apt-get install nodejs just worked.