How to install NodeJS on Ubuntu

NodeJS is open source server environment using Javascript. NodeJS use Javascript runtime built on chrome V8 Javascript engine.

How to install NodeJS on Ubuntu
How to install NodeJS on Ubuntu

What you will learn

  1. Intro to NodeJS
  2. How to Install NodeJS on Ubuntu
  3. How to use Node Version Manager(nvm)

Intro to NodeJS

NodeJS is open source server environment using Javascript. NodeJS use Javascript runtime built on chrome V8 Javascript engine.

V8 is developed by Google written in C++ and it is widely used in the Chrome.

How to Install NodeJS on Ubuntu

Default repositories of Ubuntu will contain older version of the NodeJS in order to install the latest version, first we have to update the our repos using "apt update"

sudo apt update

Install NodeJS from the repo

sudo apt install nodejs

Install Node Package Manager

sudo apt install npm

To make sure that nodejs is installed properly, let's check the installed version.

nodejs -v

If you see the version printed on your screen, We can go ahead and write your first program.

How to use Node Version Manager(nvm)

We have installed nodejs successfully but why we need this? In real world use cases we may depend on multiple node versions on different projects, to solve this problem we will use nvm.

nvm will work at the project level which is at the project folder level, if you are from the python background you may used virtualenv to do same.

Download install script for nvm

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh

Run the script using bash

bash install_nvm.sh

This script will install the nvm under your home directory ~/.nvm and updates your ~/.profile to use the nvm command globally.

Now we have to reload the ~/.profile config this can be done by re-login to your ubuntu or by running the "source" command.

source ~/.profile

All set to go! Yeah.

List nodejs version available remotely

nvm ls-remote

You will see the list of versions

    v9.10.0
    v9.10.1
    v9.11.0
    v9.11.1
    v12.16.3 (LTS)
    v14.1.0 (Latest)

LTS release status is "long-term support", which typically guarantees that critical bugs will be fixed for a total of 30 months. Production applications should only use Active LTS or Maintenance LTS releases.

How we can install the specific version

nvm install 12.16.3

How we can switch between the node versions

nvm use 12.16.3

To see the list of installed node versions you can use

nvm ls

We can set the default node version by using "alias" command

nvm alias default 12.16.3

Now new session will have the node version of 12.16.3

Conclusion

We have seen what is NodeJS, how to install NodeJS install Ubuntu and we have seen what is NVM and how to use NVM in detail.

Leave your feedback below in comments, If you like please do share and subscribe.