How to install Node.js on Ubuntu 16.04

ubuntu-nodejs

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js is a server-side programming framework, which provides event-driven, non-blocking I/O(asynchronous) and cross-platform system.

Node.js can be used to create real-time web APIs, multiplayer game servers, IOT devices API, web server etc.

You can install Node.js using many ways and easiest is using Ubuntu default repositories. This will install the Node.js older version but will be the stable one and can be used for development and testing purpose.

 

sudo apt-get update
sudo apt-get install nodejs

But to run you application in production environment you should install the latest version of Node.js directly from their repository.

Install version 8 of Node.js

sudo apt-get install curl python-software-properties
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt-get install nodejs

Check the version of installed Node.js

nodejs -v

Removing Node.js

sudo apt-get remove nodejs

This will remove the Node.js package but will retain the configuration file, in case you want to install the Node.js again with the same configurations.
 
To remove Node.js completely run below commands.

sudo apt-get purge nodejs
sudo apt-get autoremove