Resolve npm depends on node-gyp on Ubuntu 20.04

Development Nov 25, 2020

I've recently been trying to update NodeJS and NPM on a couple of my machines. Both machines started out as having Ubuntu 18.04 and have been upgraded to 20.04, and therein lies the problem. Having updated to 20.04, some of the upgrades broke the npm installation (hence the upgrade) and running apt install npm always resulted in the same message...

The following packages have unmet dependencies.
 npm : Depends: node-gyp (>= 3.6.2~) but it is not going to be installed

There's a lot of information around on how it might be possible to correct this, but none of them worked for me. At least not by themselves.

After some digging, I found that I'd previously installed NPM using the NodeSource PPA, as I needed a newer version than what 18.04 came with. As 20.04 comes with more updated versions, I wanted to revert back to using the standard Ubuntu sources.

Here's the steps I went through to be able to get NodeJS and NPM working again following the update to Ubuntu 20.04.

cd /etc/etc/sources.list.d
sudo rm -f nodesource.*
sudo apt remove nodejs
sudo apt autoremove
sudo apt update
sudo apt install nodejs
sudo apt install -y aptitude
sudo aptitude install npm

After the last command, the following message appeared

	The following actions will resolve these dependencies:

		 Keep the following packages at their current version:
	1)     libnode-dev [Not Installed]                        
	2)     libssl-dev [Not Installed]                         
	3)     node-gyp [Not Installed]                           
	4)     npm [Not Installed]                                

	Accept this solution? [Y/n/q/?]

At this point, select n to get to the next prompt, which will be

	The following actions will resolve these dependencies:

		 Downgrade the following packages:        
	1)     libssl1.1 [ (now) -> 1.1.1f-1ubuntu2

	Accept this solution? [Y/n/q/?]

Select Y at this point. This will give a message similar to the following (numbers may vary)

	0 packages upgraded, 287 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
	Need to get 7,167 kB of archives. After unpacking 36.9 MB will be used.
	Do you want to continue? [Y/n/?]

Select Y. Done!

You can now run npm -v and have a version returned. In my case I had 6.14.4.


Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.