As usual, update the system to the latest version. It’s really important to keep the system updated to avoid unnecessary risk due to bug on an older version
sudo apt update sudo apt upgrade -y
if there’s a kernel update, please restart your system to use the latest available version.
To successfully install nodejs, install the dependency
sudo apt install curl -y
curl used for downloading installation script.
Install Nodejs 16
Since the official Ubuntu/Debian repository coming with an older version of Nodejs, we’ll use a 3rd-party repository which is provided by Nodesource, it’s some kind of official version, because it’s on Nodejs documentation. By using this repository, the version installed will keep update, but not upgraded to a newer version when available. Which is expected for the right approach by package repository.
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt install -y nodejs # for development server you might need to install development tools sudo apt-get install gcc g++ make
To verify nodejs, run
using nodejs itself
node -v # output v16.1.0
check npm version
npm -v # output 7.11.2