27

Trying to upgrade nodejs on ubuntu 20.10.

Ran the official installation instructions:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

Got the following error:

The following packages will be upgraded:
  nodejs
1 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
1 not fully installed or removed.
Need to get 0 B/24.5 MB of archives.
After this operation, 119 MB of additional disk space will be used.
(Reading database ... 277425 files and directories currently installed.)
Preparing to unpack .../nodejs_14.15.4-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (14.15.4-deb-1nodesource1) over (12.18.2~dfsg-1ubuntu2) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_14.15.4-deb-1nodesource1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/doc/nodejs/api/dgram.json.gz', which is also in package nodejs-doc 12.18.2~dfsg-1ubuntu2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_14.15.4-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I've looked at other StackOverflow answers recommending that I either try to uninstall nodejs-doc (the conflicting dependency) or to run the following command:

sudo dpkg -i --force-overwrite /usr/share/doc/nodejs/api/dgram.json.gz

Neither seemed to work. In the case of the above command, it said that the file needed to be a deb package - and anyway, I'm a little skeptical about that strategy as it could break my setup.

For attempting to removing nodejs-doc, I got the following output:

You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 nodejs : Depends: libnode72 (= 12.18.2~dfsg-1ubuntu2) but it is not going to be installed
          Recommends: nodejs-doc but it is not going to be installed

I've also tried running the recommended apt --fix-broken install but it doesn't seem to help.

Patrick Moriarty
  • 271
  • 1
  • 3
  • 3
  • Just a heads up: `curl ... | sudo bash -` is terrible from a security perspective. You run code as `root` without having a chance to review it. Unfortunately, this is becoming more and more common. – Panki Jan 05 '21 at 14:53
  • https://stackoverflow.com/a/75943902/6194097 – Kushan Gunasekera Apr 05 '23 at 21:13

11 Answers11

30

All of this didn't work for me.

What worked was:

sudo dpkg --remove --force-remove-reinstreq libnode-dev
sudo dpkg --remove --force-remove-reinstreq libnode72:amd64

via

dirkk0
  • 426
  • 4
  • 5
18

You need to enable the universe repository which provide the missing dependencies libnode72 (= 12.18.2~dfsg-1ubuntu2) and nodejs-doc (12.18.2~dfsg-1ubuntu2) in Ubuntu 20.10 :

sudo add-apt-repository universe
sudo apt install libnode72 nodejs-doc

dpkg -i --force-overwrite should point to the .deb file:

sudo dpkg -i --force-overwrite  /var/cache/apt/archives/nodejs_14.15.4-deb-1nodesource1_amd64.deb
GAD3R
  • 63,407
  • 31
  • 131
  • 192
  • 1
    follow you step, it's showing dpkg: error processing archive /var/cache/apt/archives/nodejs_16.15.0-deb-1nodesource1_amd64.deb (--install): conflicting packages - not installing nodejs Errors were encountered while processing: /var/cache/apt/archives/nodejs_16.15.0-deb-1nodesource1_amd64.deb – Ng Sharma May 29 '22 at 09:35
13

Just delete nodejs-doc:

sudo apt remove nodejs-doc
Metin Celik
  • 131
  • 3
7

Other answers didn't work for me but I installed it successfully after trying these :

delete the new package source

cd /etc/apt/sources.list.d 
sudo rm nodesource.list

update apt, fix the install, remove nodejs and the nodejs-doc packages

sudo apt --fix-broken install
sudo apt update
sudo apt remove nodejs
sudo apt remove nodejs-doc

Then install node & npm normally

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

via

Muhammed Ali
  • 71
  • 1
  • 2
4

What you need to do is to remove the previous node version to avoid conflict

sudo apt remove nodejs

then, you can run:

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

sudo apt-get install -y nodejs

Mind you,

setup_18.x

can be anyone node version you want to install

Adesoft
  • 141
  • 1
4

Run these commands:

sudo apt remove nodejs  
sudo apt remove nodejs-doc
sudo dpkg --remove --force-remove-reinstreq libnode-dev
sudo dpkg --remove --force-remove-reinstreq libnode72:amd64
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt-get install -y nodejs
dr_
  • 28,763
  • 21
  • 89
  • 133
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 14 '23 at 10:28
2

I was tring to update to node from v12.x to v14.21.1, using:

curl -sL https://deb.nodesource.com/setup_14.x -o setup_14.sh
sudo sh ./setup_14.sh
sudo apt update
sudo apt install nodejs

And I had the same problem in the error, it seems that there are already a previous instillation of node packages that are not compatible anymore so

My Error message was

Unpacking nodejs (14.21.1-deb-1nodesource1) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_14.21.1-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)
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_14.21.1-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

As you can see the error said that a file from libnode-dev could not be overwritten, so I removed the lib and tried again. So another different error poped up:

dpkg: error processing archive /var/cache/apt/archives/nodejs_14.21.1-deb-1nodesource1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/systemtap/tapset/node.stp', which is also in package libnode72:amd64 12.22.9~dfsg-1ubuntu3
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_14.21.1-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

As you can see the error said that a file from libnode72:amd64 could not be overwritten, so I removed the lib and tried again. And worked

Summarizing the solution

sudo apt remove libnode-dev
sudo apt remove libnode72:amd64
sudo apt install nodejs

verifing if it worked:

node -v
v14.21.1
2

It looks like the Node.js installation is failing because there is a conflict with another package on your system (libnode72:amd64).

To resolve this conflict, you can try removing the libnode72:amd64 package and then installing Node.js again. Here are the steps you can follow:

Connect to your server using SSH.

Remove the libnode72:amd64 package:

sudo apt-get remove libnode72:amd64

Update the package list:

sudo apt-get update

Install Node.js:

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

This will install the latest version of Node.js (16.x) from the official NodeSource repository.

Verify that Node.js is installed:

node -v

This should print the version number of Node.js installed on your system.

After following these steps, you should be able to use Node.js on your server. If you encounter any other errors, feel free to ask for further assistance.

Stiloff
  • 21
  • 2
2

For those that have accidentally installed NodeJS version 12 on Ubuntu 22. Be sure to execute

sudo apt autoremove nodejs

before installing the node 18 LTS

Ocastro
  • 121
  • 2
0

What worked for me (Ubuntu 22.04.2 LTS which already has a node 12.x from OS)

Remove the one coming in the error

sudo dpkg --remove --force-remove-reinstreq libnode72:amd64
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&sudo apt-get install -y nodejs
-2

Just Write

sudo apt purge nodejs

sudo apt autoremove

sudo apt install -y nodejs 
Piyush
  • 1
  • 1
  • 2
    Could you say something about why the user should run the commands you list and how it differs from what other answers suggest? – Kusalananda Sep 14 '22 at 10:53