How to Install Latest Nodejs & Npm on Ubuntu 16.04 & 14.04

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Latest version node.js ppa is maintaining by its official website. We can add this PPA to Ubuntu 16.04 LTS (Trusty Tahr) and 14.04 LTS (Xenial Xerus) Systems and install node.js with few easy commands.

Install nodejs

Step 1: Add NodeJs PPA

First, you need to node.js PPA in our system provides by nodejs official website. We also need to install python-software-properties package if not installed already.

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

Step 2: Install Nodejs and NPM

After adding required PPA file lets install Node package. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.

$ sudo apt-get install nodejs

Step 3: Check Node.js and NPM Version

After installing node.js verify and check the installed version. You can find more details about current version on node.js official website.

$ node -v 

v7.10.0

Also, check the version of installed npm.

$ npm -v 

4.2.0

Step 4: Create Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with “Hello World!” text. Create a file http_server.js

$ vim http_server.js

and add following content

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');

Now start the web server using below command.

$ node --debug http_server.js

debugger listening on port 5858
Server running at http://127.0.0.1:3001/

The web server has been started on port 3001. Now access http://127.0.0.1:3001/ URL in browser. Now you will need to configure a front-end server for your app.

 

credit : https://tecadmin.net/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s