Fix error while installing NodeJS

The Error

If you are seeing the following error when trying to install NodeJS, I have an easy solution for you. This is the error

Preparing to unpack .../nodejs_16.20.0-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (16.20.0-deb-1nodesource1) over (12.22.9~dfsg-1ubuntu3) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_16.20.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)
Errors were encountered while processing:
needrestart is being skipped since dpkg has failed
E: Sub-process /usr/bin/dpkg returned an error code (1)
Error: Process completed with exit code 100.

The Solution

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

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

And now install the version of NodeJS you wanted. Example

curl -fsSL | sudo -E bash -
sudo apt-get install -y nodejs