In this guide, I will show how one can install node.js on ubuntu 20.04 and beyond. We will install it using apt with PPA software repository to install specific versions of the nodejs
To upgrade or install a different kind of version of node.js, one can use a personal package archive (PPA) that is extensively managed and maintained by NodeSource. The PPA have an array of versions of node.js available than the official ubuntu repositories. Node.js v12, v13, v14, and v15 are available. Refer to the NodeSource documentation
- First, let's install the PPA in order to get access and take advantage of its packages. From your home directory, use curl to retrieve the installation script for your preferred version, making sure to replace 14.x with your preferred version string. It's recommended to install LTS versions of any software.
$ cd ~ $ curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
- After the above, action the PPA will be added to your configuration and your local package cache. It will be updated automatically giving you liberty now to install the Node.js package:
$ sudo apt install nodejs
- Verify that node.js is installed aptly by simply running node with the -v version flag:
$ node -v
NodeSource nodejs package contains both the node binary and npm, so you don’t need to install npm separately.
Congratulations, you have successfully installed Node.js and npm using apt and the NodeSource PPA.