Install Node.js on CentOS/RHEL 6/7

Share It!

Node.js is a Javascript platform for server-side programming. It allows users to easily create networked applications that require backend functionality. Read more about node.js from official site.

This tutorial will help you to install node.js on CentOS / RHEL 6/7 systems with an example application.

Step #1 Install Required Packages

Run the following command to install all require packages:

# yum install gcc gcc-c++ wget

After installing require packages the development tools and screen package in your system using following commands.

# yum groupinstall "Development Tools"
# yum install screen

Step #2 Install Python

To install latest version of node.js needed Python 2.7 or above version. So make sure you have installed proper Python version. You may also refer following article to install it.

Install Python 3.5 without Removing Existing Version

Step #3 Download Node.js

Download latest node.js source code from here or just use following commands.

# cd /opt
# wget
# tar xzf node-v5.8.0.tar.gz
# cd node-v5.8.0

Step #4 Extract and Compile Node.js

Now we have extracted source of node.js and use one of below command to compile source code. If you have install Python 3.5 alternatively use second one.

# ./configure
# python3.5 ./configure 

./configure actually not compiles the source code, it only sets the compiler flags as per your system architecture ( 32/64bit ). now use below commands to actually compile the code. These commands may take more time to complete.

# make
# make install

Step #5 Check Node.js Version

Run following command to check the node.js version.

# node --version

Step #6 Configure Example Application using Express

First we required to install npm modules using following commands.

# npm -g install express supervisor express-generator

This time is to create application using express and npm using below set of commands.

# express technical
# cd technical
# npm install 
# screen

The above commands will create a directory myapp and npm will install all the required modules to run your application from its software repository.

Now edit views/index.jade and add following content to show on default page.

# vim views/index.jade
extends layout

block content
  h1= title
  p Welcome to Technical World

Finally start your application using supervisor.

# supervisor ./bin/www

This application by default start on port 3000. Access your application by connecting your server on port 3000 in your browser.



Enjoy it!

Leave a Reply

Your email address will not be published.