2

I'm trying to upgrade my NodeJS 12.22.09 to version 16 or newer, but when I enter the command sudo apt update && sudo apt upgrade it returns this error below:

Preparing to unpack …/12-nodejs_16.16.0-deb-1nodesource1_amd64.deb …
Unpacking nodejs (16.16.0-deb-1nodesource1) over (12.22.9~dfsg-1ubuntu3) …
dpkg: error processing archive /tmp/apt-dpkg-install-hIlTWe/12-nodejs_16.16.0-deb-1nodesource1_amd64.deb (—unpack):
 trying to overwrite ‘/usr/include/node/common.gypi’, which is also in package libnode-dev 12.22.9~dfsg-1ubuntu3
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack …/13-snapd_2.56.2+22.04ubuntu1_amd64.deb …
Unpacking snapd (2.56.2+22.04ubuntu1) over (2.55.5+22.04) …
Errors were encountered while processing:
 /tmp/apt-dpkg-install-hIlTWe/12-nodejs_16.16.0-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

How to solve this problem?

knocte
  • 16,941
  • 11
  • 79
  • 125

3 Answers3

8

There is a npm package called "n" that handles node version management. Additionally, it supports convenient version naming, such as "current, "lts" or "18.12.1".

So, in your shell, type these commands:

sudo npm install -g n
sudo n lts
velis
  • 8,747
  • 4
  • 44
  • 64
Eren
  • 81
  • 1
  • 2
  • 2
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – nima Oct 31 '22 at 06:38
0

It seems like nodejs and libnode are having a conflict because they are trying to install the same file '/usr/include/node/common.gypi' which is causing an error. To solve this, you can first remove the libnode package by using sudo apt remove libnode-dev. Once it is removed, you can retry the nodejs upgrade command sudo apt update && sudo apt upgrade.

0

sudo npm install -g --force node@latest

Use that command, and it will fix your problem. The only issue with that is it will rewrite your node folder.

Hoang Dao
  • 775
  • 5
  • 16