Install latest Nodejs And NPM in Ubuntu

By | January 17, 2019

This tutorial is about to Install latest Nodejs And NPM in Ubuntu.

Note: Tested with Ubuntu 16.04 / 18.04 LTS

Nodejs is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. Nodejs lets developers use JavaScript to write command line programm tools and is for server-side scripts to produce dynamic web page content before the page is sent to the user’s web browser. Consequently, Nodejs represents a “JavaScript everywhere” paradigm, unifying web application development around a single programming language, rather than different languages for server side and client side scripts.

For more about Nodejs, Visit website

To get started with install Nodejs and NPM, Follow below steps:

Step 1: Add Node.js PPA

The first step is to add node.js

Before installation of Nodejs latest version, you should add its PPA to Ubuntu. This repository is provided by the trusted official package maintainer. To add the repository, run the below commands.

sudo apt install curl

There are two repositories you can install. first repository includes latest Nodejs packages and the second has the LTS or (Long Term Support) packages. if you need the latest then install the first repository for the same.

At other hands, if you want more stable and tested Nodejs packages, then install the LTS repository.

Then for the Latest release, add below PPA.

curl -sL | sudo bash -

To install the LTS release, use this PPA

curl -sL | sudo bash -

After that you can install latest version of Nodejs from the specific repository you choose. If you add both repositories, the latest version of Nodejs will be installed and not the LTS.

Step 2: Install Nodejs and NPM

To install, run the commands below

sudo apt install nodejs

After installing, both Node.js and NPM modules should be installed and ready to use

You can use the commands below to view the version number installed

> node -v
> npm -v

To test whether the webserver is properly installed, run the commands below to

Create a test file called server.js in your home folder.

> cd ~/
> nano server.js

Then copy and paste the content below into the file and save

const http = require('http');

const hostname = '';
const port = 8585;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Its working!\n');

server.listen(port, hostname, () => {
  console.log(<code>Server running at http://${hostname}:${port}/);

After that save the file and run the commands below to start the server

node server.js

You should see an output that reads:

Server running at

Now open your browser and write the hostname or IP address followed by port 8585. and you should see a default page with “Hello World”

Install latest Nodejs And NPM in Ubuntu
Nodejs is running…

Finally, you are done with installing Nodejs and NPM!

To check other articles visit our homepage

so this is the article about Install latest Nodejs And NPM in Ubuntu. Happy Codding !!

4 thoughts on “Install latest Nodejs And NPM in Ubuntu

  1. canadianorderpharmacy

    Hello, all is going nicely here and ofcourse every one is sharing facts, that’s genuinely excellent, keep up writing.

  2. Pingback: Hello World tutorial in Laravel with Vue js and vutiefy - < CodesCompanion />

Leave a Reply

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