In this tutorial, you will learn how to install NodeJS on Ubuntu from the NodeSource repository. Basically there are 4 easy Steps to Install Node JS in Ubuntu 20.04 from NodeSource repository
Step 1 – Update Your System
The first step is to update the package list, which will make sure that your system is up-to-date with all the latest bug fixes and security patches.
To update the package list, open a terminal window and type the following command:
# sudo apt update && sudo apt upgrade -y
Step 2 – Add Node Repository and Update Package List for Node JS
In this step, you will need to add a new repository to your system. This is because the default repositories are not up-to-date with the latest version of Node.js. The repository you will be adding is called nodejs.org and it will include the latest version of Node.js, which is 18.x at the time of writing this tutorial.
# curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Step 3 – Installing Node JS with apt-get Command
In order to do this, open up your terminal and type in “sudo apt-get install nodejs”. This will add the new repository to your system and update your package list with all available packages from that repo (all).
# sudo apt-get install nodejs
For those of you who are not familiar with apt-get commands, it is a package management system for Debian-based Linux distributions. It allows users to install and remove software packages from their computer.
Step 4 – Verify Installation of NodeJS
# node --version
Install Node.js via NodeSouce repository will download you latest version of Node.js in your ubuntu operating system. However if you want default version, using Ubuntu official repository is sufficient.