Ubuntu – Upgrading nodejs on Ubuntu: How to fix broken pipe error

aptdpkgUbuntu

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.

Best Answer

Just delete nodejs-doc:

sudo apt remove nodejs-doc
Related Question