How to install node js in ubuntu LEARNOVITA

How to Install Node.JS on Ubuntu | Everything You Need to Know

Last updated on 28th Oct 2022, Artciles, Blog

About author

Yuvanash (Angular Js and Node js Developer )

Yuvanash has an intense knowledge of HTML5, Javascript, Angular, React JS, Node JS, Express, StrongLoop, Git, Jade, EJS, etc. He is a certified professional with 7+ years of experience in their respective domains.

(5.0) | 19487 Ratings 2219

Being able to install a Node.js on Ubuntu or other OS is a boon for a JavaScript users worldwide. Learning one language that would serve all the development needs is a goldmine in a tech world. Before Node.js, a JavaScript folks were compelled to learn second language that helped them perform all their backend activities, a pain in a neck.

    • In this article you will learn:
    • 1.What is Node.js? 
    • 2.Prerequisites
    • 3.How to Install Node.js on Ubuntu [Step-by-Step]
    • 4.How to Verify the Installation
    • 5.Create Demo Web Server
    • 6.How to Use the Node.js on Ubuntu
    • 7.How to Uninstall Node.js from Ubuntu?
    • 8.Uninstall Using NVM
    • 9.Advantages of Using Node.js

What is a Node.js?

  • Node.js is not programming language, some newbies think it is, but it’s not! It is open-source JavaScript runtime environment that executes a JavaScript codes outside a browser. What Node.js simply does is repackage functionalities and features of a JavaScript language into modules. It also upgrades it to run an outside the browser which was original run-time environment for the Language.
  • Because these upgrades are packaged into a Node.js developers can now use a JavaScript for frontend and backend development making JavaScript full-stack language.
  • In a past, Node.js was only designed to serve a real-time performance, and push back architectures. Since then, Node.js has developed into a crucial component of a server-side scripting for event-driven, non-blocking servers. Today, Node.js powers most traditional websites and also API services.
  • Node.js uses event-driven, non-blocking I/O architecture and also V8 JavaScript runtime engine as its primary power source.

Who Uses a Node.js:

Millions of websites all around a world use Node.js. It has millions of downloads as can be seen by its weekly a npm installations. JavaScript full-stack developers enjoy a comfort Node.js brings to technology space. This is because Node.js enhances the performance of developers and facilitates a development process. Top companies that use a Node.js include:

  • NASA
  • Twitter
  • Netflix
  • LinkedIn
  • PayPal
  • GitHub
  • eBay
  • Walmart
  • Spotify
  • Medium

If research these companies will notice that they base their companies’ operations on a numerous services or goods. However, all share a vital characteristic which is that all rely on a Node.js. No matter what business, employing Node.js can solve most of the development problems.


Before installing an updated node version on ubuntu, and must ensure that you’ve accumulated all necessary knowledge. Also, make sure have downloaded all required installation files and elements. First, it would help a lot if had a basic understanding of a JavaScript and its syntax. This enables to pick up a Node.js easily. Secondly may work on a server-side coding by having a basic grasp of object-oriented programming (OOP) language.

Hardware Requirements:

  • Node.js does not need complex hardware configuration to work; most machines nowadays are be compatible.
  • Node.js installation needs a stable hard drive for it to work.
  • Should have the necessary pre-requisites to an install Node.js on Ubuntu.
  • Virtually all the modem computers can run Node.Js, including the miniature computers like a BeagleBone or Arduino YÚN.
  • The Random-Access Memory (RAM) of the system should be up to 4GB and system storage should at least to be 256GB of Hard Disk Space.
Node.js Architecture

Software Requirements:

  • Below are software requirements for an installing Node.js on Ubuntu. Web Browser should be an intact. Any browser like Google Chrome, Mozilla Firefox, or Microsoft Edge can run a Node.js.
  • Operating System should be an accurate and free, having an Ubuntu server installed with the non-root Sudo user and firewall.

How to Install a Node.js on Ubuntu [Step-by-Step]:

Follow two methods below to install a Node.js on your Ubuntu machine.

Method 1: Installing a Stable Version for Ubuntu

Before can install a stable version of a Node.js for Ubuntu, must update a terminal first.

Step 1:  You can use apt package manager to obtain a version that can run Node.js. Update the index for a regional package usage. $ sudo apt update.

Step 2:  Install Node.js from a repository in step two. $ sudo apt install Node.js.

Step 3:  Install a npm ubuntu with a code below. $ sudo apt install npm.

Step 4:  Use this to check which Node.js version are installed. $ Node.js -v && npm –version.

Method 2: Install a Node.js Using a PPA

  • Software repositories of different packages specifically created for a Ubuntu 20.14 users are included in a PPA repository. The PPA repository for most recent Node.js version is an added first.
  • Before installing a Node.js using PPA, ensure that have a curl command-line utility installed on a system. If curl isn’t installed on a system paste this command on the terminal to install curl: $ sudo apt install curl .
  • After installing a curl add the Node.js source with following code. $ curl -fsSL https: // / setup_18.x | sudo -E bash.
  • If experience an issue with a public such as “the following signatures couldn’t be verified because public key is not available”.
  • Now, on console, should see a public key; copy it, replace it in a <"PUBLIC KEY"> space below, and run it on terminal. $ sudo apt-key adv –keyserver –recv-keys <"PUBLIC KEY">.
  • Now run a command below to install a Node.js npm Ubuntu 20.04 on machine. $ sudo apt-get install -y Node.js.
  • If have done everything correctly, Node.js will successfully install on a Linux distribution. To check a node version Ubuntu, run the command shown below and newest version is installed. node -v && npm –version.

How to Verify an Installation :

Now have installed Node.js, and can verify the installation to check if the installation was successful. To confirm an installation, you must run a following Linux commands on a terminal.

To check a Node.js version type: $ node -version 

And to check a npm version, type: $ npm –version

Node.js and npm version names should be displayed on a terminal if they were successfully installed.

Create a Demo Web Server:

Step 1: Open the code editor and select working directory.

Step 2: Create the new file called index.js in a root of the working directory.

Step 3:  Copy and paste a codes below inside an index.js file.

  • const express = require(‘express’);
  • const app = express();
  • [Text Wrapping Break]
  • app.get(‘/’, function (req, res) {
  • res.send(‘Hello World!’);
  • });
  • app.listen(3000, function () {
  •   console.log(‘Example app listening on a port 3000!’);
  • });

Step 4:

  • Now run a server with the code below on a terminal.
  • $ node index.js .
  • Result will appear as example app running on a port 3000.

Step 5:  And that’s how create a web server with a Node.js.

How to Use a Node.js on Ubuntu:

Using Node.js on a Ubuntu is simple, just as would use it on the other operating systems.

STEP 1: Create a file called index.js in a root of working directory.

STEP 2: For this example, let’s create a simple function that adds a two values together. Copy and paste a code below into an index.js file.

  • function add(y,z) {
  •   return y+z;
  • }
  • console.log(add(81, 9))

STEP 3: Execute a code by running $ node index.js on a terminal which would result in output below:

// 90

How to Uninstall a Node.js from Ubuntu?

The following instructions remove a Node.js from an Ubuntu system.

  • $ sudo apt remove Node.js
  • $ sudo apt purge Node.js -y
Installing Node.js on Ubuntu

Uninstall Using a NVM:

First check to see if it is most recent active version:

  • $ nvm current

Now deactivate a version using a command below:

  • $ nvm deactivate

Advantages of Using a Node.js:

The correct programming platform for a tech stack is just as crucial as amount of labor wish to commit to it. When determining a benefits of utilizing a specific platform, a variety of criteria should be a considered. The total benefit distribution may be changed by the factors including a learning curve, the rate of a development, the community, and scalability. The following are key benefits of an utilizing Node.js:

  • Simple syntax
  • Simple to learn new skills
  • Quick scaling ability
  • Flexible and open source
  • Cross-platform programming
  • Full-stack single-language development
  • Instantaneous communication
  • A sizable and vibrant community

Are you looking training with Right Jobs?

Contact Us

Popular Courses