How to Install node js in ubuntu ? Easiest Guide out there
The default package manager of Node.js is NPM. Node.js comes in two versions or one may call it releases. The first is “LTS” and the second is “Current”. Well, here we will discuss the installation methods for both the versions. But before that let us see what the two versions are:
- LTS: The LTS or the Long term support release. This receives an 18 month of active support and further 12 months of maintenance.
- Current: As it sounds by the name it is the current version and which under active development. Node.js releases a new version almost every 6 months.
So, today we will see how to install node.js on Ubuntu so that you can begin with your coding. Also, we will see a detailed explanation of various terms at every step so that you will know what you are doing to install Node.js.
Before moving to the steps let us see some of the basic requirements that you need in order to install node.js :
- You must have Ubuntu installed on your system.
- You must have sudo privileges set up on your system. And the most important thing you need to remember the sudo password because before installation Ubuntu will ask your sudo password at some steps.
So, let’s begin:
3 Ways to Install node js in ubuntu
Method 1: Using NVM to install Node.js:
NVM stands for Node.js version manager. This is another alternative method to install node.js using a tool called NVM. Most of you must have heard about RVM or Ruby version manager for the Ruby language, well NVM is somewhat similar to that.
NVM works at the level of Independent directory in your home directory rather than working at the operating system level.
In short terms, this means that you can install multiple versions of Node.js on the same system or machine. Every version installed runs in its own environment so you can switch between the versions without affecting the entire system.
So, NVM helps the developers and users to manage with the previous releases of Node.js along with the access of latest versions.
So, at first, you will need to install NVM on your system. Using a bash script you can install NVM, run the command given below to install NVM on your system:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Now you need to reload the system environment. This will set the required environment variables that are required for NVM to be used on your system
- source ~/.profile //for Debian based systems
- source ~/.bashrc //for Centos/RHEL systems
Now you have installed NVM on your system. Now all you need to do is find out the available versions of node.js that you can install, run :
Well, after running the above command you will be able to see a list of the version of Node.js. You have almost on the final step now.
To install Node.js just select the version that you want to install and run the following command:
Nvm install v10.16.0 //(you can select any version from the list of versions available to you)Also check 7 Best download manager Ubuntu / Linux
Method 2: Install Node.js via snap:
Installing something via snap is a very easy method. Snaps are containerized software packages that are simple to install and create. Snaps are designed to work across IoT devices, cloud, desktop.
Actually, these snaps are applications that are packaged with all their dependencies to run on almost all the popular distributions of Linux from a single build. This allows them to update automatically.
This feature of auto-updating makes them a good choice to deliver desktop applications.
The Node.js snap package contains the widely popular package managers, Yarn, and NPM. To install via snap the commands are as follows:
- Install snapd
- Sudo apt update
- Sudo apt install snapd
Now, most of you might be thinking about what is snapd. Snapd is a service that manages and runs the snaps for you. So, after these commands you need to install node.js via snap by running the commands given below:
For LTS release:(version 10):
sudo snap install node --channel=10/stable --classic
For current release:(version 11):
Method 3: Installing using a PPA:
This is another alternative method to install node.js on your system. PPA or personal package archive is a software repository for uploading the source packages to be published and built as an APT repository.
The Ubuntu operating system gets a new version at regular intervals and that comes with all the updates of your favorite software.
But in some cases, if a new version of your favorite software gets released then you might have to wait for some more time till a new version of Ubuntu comes.
So, PPA helps here and provides the users and developers the latest version of software and applications.
Before installing Node.js on your system you need to have PPA working. To continue you have to run the following commands to install all the required dependencies.
sudo apt install build-essential curl
As discussed above there are two repositories the LTS and the current. So if you want the LTS packages then you need to install the LTS repository by using the following commands :
For LTS add this PPA
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
And if you want the current version of node.js then run the following commands:
For Current add this PPA
curl -sL https://rpm.nodesource.com/setup_11.x | bash -
Once you are done with the steps given above then you are all set to install node.js all you have to do is run the commands given below:
sudo apt install Nodejs \
After this Node.js will be installed on your Ubuntu operating system. To check whether it is installed or not you can run the following command:
node –v (to check the version of node.js) npm –v (to check the version of Npm)
And, here you go you have installed Node.js on your Ubuntu operating system.