In this tutorial we will cover the steps needed to install Node.js on your CentOS 6.4, Debian or Ubuntu platform. Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. The Node.js applications are written in JavaScript, and can be run within the Node.js engine.

Requirements

  • CentOS 6.4, Debian or Ubuntu installed on your computer/server
  • SSH access (Command line access to the server)
  • root privileges
  • Basic skills for working on a Linux environment

Install Node.js in CentOS 6.4

For the Node.js installation we will use the default package manager included inside the corresponding Linux distribution.

The platform requires the Development tools group to be installed on the CentOS 6.4 server:

Also we will need the screen software later so if the command is not included inside your Linux distribution you should install it:

The Node.js will be compiled from the latest available source package:

You should configure the compiler and compile the source code:

Bear in mind that the process might take some time. Once done you can install Node.js:

Install Node.js in Debain

Again we will build the software from the source package:

Install Node.js in Ubuntu

In order to obtain the latest Node.js version the correct repository should be added first:

After that you can continue with the installation:

Test the functionality of the Node.js service

In order to check if everything went well you can execute the following commands:

You can also use the terminal to output a simple message:

the displayed result should be:

You can exit the prompt by pressing Ctrl+C twice.

In order to check the functionality of the Node.js software through a browser we can use the following sample script:

The script can be placed into a .js file, i.e. test.js. The script “tells” the engine to listen on port 3000 and as result it will display a sample “It is working!” message.

Make sure that port 3000 is allowed inside the server's firewall:

CentOS 6.4

Debian/Ubuntu:

You can test the test.js script using the Node.js command:

The process will be executed as foreground one inside the terminal. It can be cancelled with Ctrl+C.

If you want to start a detachable session you can use the screen command:

The session can be detached with the keyboard shortcut Ctrl+A+D

In case you want to access the session again you can use:

Access the test script using your browser:

or

where X.X.X.X is your server's IP address, i.e. http://1.2.3.4:3000

You should be able to see the output from the test.js script inside your browser.

An easy way to find your server's IP address is to execute the following command: