How to Install Node.Js and Npm On Ubuntu 18.04

by Luigi Nori Date: 24-04-2020 node.js javascript js npm

Node.js is a JavaScript platform for general programming that allows users to create network applications quickly. By leveraging JavaScript in both frontend and backend, Node.js makes development more uniform and integrated. Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. runtime for easily building fast, scalable network applications. In this guide, we'll show you how to get started with Node.js on an Ubuntu 18.04 server.

You can add the PPA to your Ubuntu 18.04 LTS systems and install node.js on Linux VPS with a few easy commands. To start the process you should have a non-root user account with sudo privileges set up on your system


Add Node.js PPA from NodeSource

Ubuntu 18.04 contains a version of Node.js in its default repositories that can be used to provide a consistent experience across multiple systems. You can select which version you want to install on the system. Add the following PPA's to your system to install Nodejs on Ubuntu.

To get a more recent version of Node.js you can add the PPA (personal package archive) maintained by NodeSource. 

sudo apt-get install curl  curl -sL | sudo -E bash -  

Or you can use the most recent LTS release available.

sudo apt-get install curl  curl -sL | sudo -E bash -  

Install the package Version from Ubuntu repositories or from NodeSource PPA

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

sudo apt update  
sudo apt install nodejs 

If you also want to install npm, the Node.js package manager. You can do this by typing:

sudo apt install npm

This will allow you to install modules and packages to use with Node.js.

After installing node.js verify and check the installed version.

node -v    

Check the npm version

npm -v    

Create a Demo Test Web Server

If you want to test your node.js install you can create a web server with “Hello World!” text. Create a file server.js

nano test-server.js  

and add the following content

  var http = require('http');
  http.createServer(function (request, response) {
      response.writeHead(200, {
			'Content-Type': 'text/plain'
       response.end('Hello World from Noden');  
	}).listen(1333, "");  
   console.log('Server running at');

Now start the Node application using the command.

  node test-server.js
  debugger listening on port 5858  Server running at  

You can also start the application with debugging enabled with the following commands.

  node --inspect test-server.js    
  Debugger listening on ws://
  For help, see:
  Server running at  

The web server has been started on port 1333. You can access it from URL in browser. Now you will need to configure a front-end server for your app.


Removing Node.js

You can uninstall Node.js using apt, to remove the distro-stable version, you will need to work with the apt utility at the system level.

To remove the distro-stable version, type the following:

sudo apt remove nodejs

This command will remove the package and retain the configuration files. These may be of use to you if you intend to install the package again at a later point. If you don’t want to save the configuration files for later use, then run the following:

sudo apt purge nodejs

This will uninstall the package and remove the configuration files associated with it.

As a final step, you can remove any unused packages that were automatically installed with the removed package:

sudo apt autoremove 



by Luigi Nori Date: 24-04-2020 node.js javascript js npm hits : 1680  
Luigi Nori

Luigi Nori

He has been working on the Internet since 1994 (practically a mummy), specializing in Web technologies makes his customers happy by juggling large scale and high availability applications, php and js frameworks, web design, data exchange, security, e-commerce, database and server administration, ethical hacking. He happily lives with @salvietta150x40, in his (little) free time he tries to tame a little wild dwarf with a passion for stars.


Related Posts

Why You Should Hire Node.js Developer for Your Backend Development

When developers are building a new website, they mainly focus on both frontend and backend development. The frontend code helps create the interfaces through which the app interacts with the…

Javascript: what are callbacks and how to use them.

Today we are going to learn about a concept that is widely used in javascript and that is used quite a lot by today's frameworks, libraries, especially NodeJS. This is…

HTTP Cookies: how they work and how to use them

Today we are going to write about the way to store data in a browser, why websites use cookies and how they work in detail. Continue reading to find out how…

The package managers npm and yarn: main differences

Npm and yarn are package managers that help to manage a project’s dependencies. A dependency is, as it sounds, something that a project depends on, a piece of code that…

The Javascript asign() method to merge and clone objects

In this article, we will be covering Object.assign()method in javascript in detail with examples. A javascript object is a collection of key-value pairs. Keys are also known as properties of object. Keys…

All the javascript functions and methods to manipulate arrays

This article will show that the prominent JavaScript array functions are .map(), .filter(), and .reduce(), and will then go through examples of instances in which .every() and .some() would save…

TypeScript: The evolution of JavaScript

When you're involved in the development of a large project, programming languages like JavaScript don't seem to be the best solution. Their lack of elements such as Language Aids has…

Awesome JavaScript Games and Js Software to create Games

Best sites js13kGames 2019 - Highlights from the js13kGames 2019 competition. js13kGames 2018 - 13 Games in ≤ 13kB of JavaScript. js13kGames 2017 - Build a game in 13kB or less with js13kGames. Adventure Triangle:…

Is JavaScript good for machine learning?

One of the things you always hear when you are talking to someone related to the M.L. world is that, one must learn Python because the vast majority of the…

First steps into JavaScript – a practical guide 3

After we learned the basic ofaccessing DOM elementsandhow to modify them,we are ready for the more exciting parts – handling DOM events. This allows us to make our web way more…

JavaScript: Promises explained with simple real life examples

Handling asynchronous data flows is complex, who hasn't faced codes like this one?: checkWeather('palma de mallorca', (error, weather) => { if (error) throw error; if (weather === 'well') { return checkFlights('palma…

First steps into JavaScript – a practical guide 2

In the previous aticleFirst steps into JavaScript – a practical guidewe covered the basics of the DOM and its relation to us becoming JS literate. Now that we know how…