In this tutorial you will learn to install nodejs in two methods on your Linux.

Method 01: Installing Node.js with Apt from the default repositories

To get this version, you can use the apt package manager. Refresh your local package index first by typing below command

sudo apt update

Then install Node.js:

sudo apt install nodejs

Check that the install was successful by querying node for its version number:

node -v

Method 02: Installing Node Using the Node Version Manager

The Node Version Manager allows you to install and maintain many different independent versions of Node.js, and their associated Node packages, at the same time.

Before piping the command through to bash, it is always a good idea to audit the script to make sure it isn’t doing anything you don’t agree with. You can do that by removing the | bash segment at the end of the curl command

curl -o-

Take a look and make sure you are comfortable with the changes it is making. When you are satisfied, run the command again with | bash appended at the end. The URL you use will change depending on the latest version of nvm, but as of right now, the script can be downloaded and executed by typing

curl -o- | bash

This will install the nvm script to your user account. To use it, you must first source your .bashrc file:

source ~/.bashrc

If you are using the interactive terminal to test installing Node.js with nvm, you will need to source your the ~/.bash_profile file instead. Use the following command to do so

source ~/.bash_profile

Now, you can ask NVM which versions of Node are available using below command

nvm list-remote

Now you can install any version of Node by typing any of the release versions you see. For instance, to get version v14.15.0, you can type the below command

nvm install v14.15.0

To set the specific node version as default use the below command

nvm default alias 14.15.0

If you have more than one node version installed on your system, then you can switch the specific node version using below command

nvm use 14.15.0

Leave a Reply

Your email address will not be published. Required fields are marked *