The installation of nodejs on Ubuntu 20.04 and later is demonstrated in this guide. To install particular versions of the nodejs, we will install it using the apt PPA software repository.
A personal package archive (PPA), which is actively handled and maintained by NodeSource, can be used to upgrade or install a new type of nodejs version. Nodejs versions are accessible in a wider variety on the PPA than in the official Ubuntu repositories. There are nodejs versions 12, 13, 14, 15, 16, and 18 available. Take a look at the NodeSource documentation for more information.
- Installing the PPA will let you to access and use its packages, so let's do that first. Use curl to get the installation script for your choice version from your home directory, being sure to replace 16.x with your chosen version string. Any software should be installed in LTS versions.
$ cd ~ $ curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
- The PPA will be added to your configuration and local package cache after you take the aforementioned action. You'll now have the freedom to install the nodejs package because it will be updated automatically:
$ sudo apt install nodejs
- Run node with the -v version flag to ensure that nodejs is properly installed:
$ node -v
Npm does not need to be installed individually because it is included in the NodeSource nodejs package together with the node binary.
With apt and the NodeSource PPA, you have successfully installed nodejs and npm.