Updating Node.js & npm on Ubuntu 20.04
Learn how to resolve Node.js and npm version conflicts on Ubuntu 20.04 with this step-by-step guide. It covers uninstalling outdated versions, adding NodeSource repositories, handling signature verification issues, and installing the latest Node.js version. Ensure smooth operations for your Laravel projects and more.
I recently encountered an issue when using npm install for a Laravel project:
ERROR: npm is known not to run on Node.js v10.19.0
You'll need to upgrade to a newer Node.js version in order to use this
version of npm. You can find the latest version at https://nodejs.org/
After trying several solutions, including uninstalling and reinstalling Node.js and npm, I found a reliable fix. Here’s a step-by-step guide to resolve this issue and fix common signature verification problems on Ubuntu.
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FE7097963FEFBE72
Uninstalling npm and Node.js
First, remove the current versions of npm and Node.js:
sudo apt purge npm nodejs
Optionally, clean up unnecessary files:
sudo apt autoremove
Installing Newer Versions of Node.js
We will use the custom Personal Package Archives (PPAs) from NodeSource Node.js Binary Distributions.
Of course, at this point, you want to ensure your system is supported for this edition, and you also want to consider which recent version of nodejs you may want to use for your system. I decided to go for version 16.x, while the recommended version was 14.x at the time i wrote this article. Any version from 12.x to 18.x versions are okay.
NOTE: the process is the same for all versions, but you will need to adjust the nodejs version in the commands prompt.
If you previously used Chris Lea's Node.js PPA, remove it:
sudo add-apt-repository -y -r ppa:chris-lea/node.js
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
Add the NodeSource Package Signing Key
KEYRING=/usr/share/keyrings/nodesource.gpg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
gpg --no-default-keyring --keyring "$KEYRING" --list-keys
Add the Desired NodeSource Repository
VERSION=node_16.x
DISTRO="$(lsb_release -s -c)"
echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
Update Package Lists and Install Node.js
sudo apt-get update
If you encounter the following error:
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FE7097963FEFBE72
Fix it with:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys FE7097963FEFBE72
Finally, install Node.js:
sudo apt-get install nodejs
This should resolve the issue. I hope this guide helps you fix your Node.js and npm problems on Ubuntu 20.04.
