How to install nodejs 5.6.0 on Linux

Nodejs is a platform built with V8. V8 is Google’s open source, high performance JavaScript engine. Node.js is not written in JavaScript & It is written in C++ and it uses the JavaScript language as an interpretive language for server-side request/response processing. V8 is used in Google Chrome, Google’s open source browser. Node.js server-side platform uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. NodeJS team proudly announced the latest release of NodeJS v5.6.0 change log on February 09, 2016.

1) Install Nodejs Manually in Linux

Use the below steps to install node.js to all the linux distro such as CentOS, RHEL, Fedora, Ubuntu, Debian, openSUSE & Mint. distributions from source archive.

# Prerequists for RPM based systems #
$ sudo yum -y groupinstall "Development Tools"

# Prerequists for DEB based systems #
$ sudo apt-get -y install build-essential
$ sudo apt-get install g++ curl libssl-dev apache2-utils

# Download archive file #
$ sudo wget https://nodejs.org/dist/v5.6.0/node-v5.6.0.tar.gz

# Extract, configure & install #
$ sudo tar -zxvf node-v5.6.0.tar.gz
$ cd node-v5.6.0.tar.gz
$ ./configure
$ make
$ make install

2) Install Nodejs via npm

Use the below steps to install node.js through npm package.

# Install npm package #
$ sudo yum install npm
$ sudo apt-get install npm

# Install n module #
$ sudo npm install -g n

# Install nodejs #
$ sudo n stable

3) Install Nodejs through nodesource

Use the below steps to install node.js through nodesource package. For more details about nodesource.

# For Ubuntu #
$ curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
$ sudo apt-get install -y nodejs

# For Debian #
# curl -sL https://deb.nodesource.com/setup_5.x | bash -
# apt-get install -y nodejs

# For RHEL/CentOS/Fedora #
# curl -sL https://rpm.nodesource.com/setup_5.x | bash -
# yum install -y nodejs
# dnf install -y nodejs

4) Upgrade Nodejs through npm

For Upgrade nodejs, just follow the method-2 because i have upgraded my old installation.

# Checking nodejs version #
$ node -v
v0.10.32

# Install npm package #
$ sudo yum install npm
$ sudo apt-get install npm

# Install n module #
$ sudo npm install -g n

# Install nodejs #
$ sudo n stable

# Checking Upgraded nodejs version #
$ node -v
v5.6.0

5) To interactive node.js shell

If you successfully installed nodejs on your linux box, you can interactive node.js shell. See below

# node
> console.log('Hello World');
Hello World
undefined
>.exit

6) Writing node.js program

create a file with .js extension and put above one line code [console.log(‘Hello World’);] to create simply nodejs script (I’m creating test.js file).

# node test.js
Hello World

7) How to create simply HTTP server using node.js

create a file with .js extension and put below code to create simply create simply HTTP server using node.js (I’m creating web.js file).

# nano web.js

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

To start the server, type the below command (you need to mention your .js file name)

# node web.js
Server running at http://127.0.0.1:8080/

Navigate your browser to http://127.0.0.1:8080/ and see the below output.
how-to-install-nodejs-manually-in-linux-5
Now you successfully installed and tested nodejs.

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

5 Comments on “How to install nodejs 5.6.0 on Linux”

Leave a Reply

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