Error Upgrading Nodejs

└─# apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 nodejs : Depends: libnode72 (= 12.21.0~dfsg-5) but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

When running apt --fix-broken install:

└─# apt --fix-broken install                                              100 ⨯
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libfuse3-3 libjs-highlight.js nodejs-doc
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  nodejs
The following packages will be upgraded:
  nodejs
1 upgraded, 0 newly installed, 0 to remove and 1133 not upgraded.
Need to get 0 B/26.2 MB of archives.
After this operation, 122 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 413977 files and directories currently installed.)
Preparing to unpack .../nodejs_16.9.0-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (16.9.0-deb-1nodesource1) over (12.21.0~dfsg-5) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_16.9.0-deb-1nodeso
urce1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/doc/nodejs/api/process.html', which is also in 
package nodejs-doc 12.21.0~dfsg-5
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_16.9.0-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
                                                    

What should I do?


Very rarely does this happen, but you may need to bring out the big guns for this one:

  1. Open Terminal (if it's not already open)
  2. Force an overwrite for the Node package:
    sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_16.9.0-deb-1nodesource1_amd64.deb
    
  3. Fix the rest of the broken install:
    sudo apt -f install
    
  4. Make sure the rest of your system is properly up to date:
    sudo apt update
    sudo apt dist-upgrade
    

Try not to let things get crazy enough to see messages like:

1 upgraded, 0 newly installed, 0 to remove and 1133 not upgraded.