Install Node.js on CentOS 7

Install Node.JS on CentOS 7

Introduction

What is node.js?

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications. Node.js 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.


Prerequisites

To install node.js we will need the following:

  • Node.js source downloadable from http://nodejs.org/dist
  • a SSH client either putty or bitvise
  • root access to our vps server from vpsserver.com

Once all is ready we can now start install node.js on our server.


Installing node.js from NVM

NVM or Node Version Manager is a piece of software that allows you to install and maintain many different independent versions of node.js and their associated node packages.

before we can install node.js on our machine we need to download and install NVM from GitHub. We can do this by the command.

curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh | bash

This will install nvm version 0.13.1 but we will need to use first our bash_profile to use nvm.

source ~/.bash_profile

Then we run nvm to get a list of node version available for installation.

nvm list-remote

You will see the list like below:

...
...
v5.11.1
v5.12.0
v6.0.0
v6.1.0
v6.2.0
v6.2.1
v6.2.2
v6.3.0
v6.3.1

You can install a version by typing nvm install and the version you need, for example.

nvm install v6.3.1

To install another version, type the above commands again with a differnet version at the end.

You can see which versions you have installed by typing:

nvm list

The result would be:

[root@node ~]# nvm list
->    v6.3.1
      system

To switch between versions you can do.

nvm use v6.3.1

The result would be:

[root@node ~]# nvm use v6.3.1
Now using node v6.3.1

To set a version as default you can execute.

nvm alias default v6.3.1

the corresponding result shall be:

[root@node ~]# nvm alias default v6.3.1
default -> v6.3.1

Installing node.js from Epel Repository

An alternative method of installing node.js is from the Epel Repository that is available for CentOS and other linux distro's. To get access to the repo you must first install the epel-release by.

sudo yum install epel-release

Press y for yes and let it install.

After that you can just install node.js from yum.

sudo yum install nodejs

To verify the installed version you can do.

node --version

To output shall be:

[root@node ~]# node --version
v6.3.1

Installing node.js from Source

One way of acquiring Node.js is to obtain the source code and compile it yourself.

To do so, you should grab the source code from the project's website. On the downloads page[1], right click on the "Source Code" link and click "Copy link address" or whatever similar option your browser gives you.

The current release version that node.js has is v6.3.1. We will download it using wget.

wget https://nodejs.org/download/release/v6.3.1/node-v6.3.1.tar.gz

Then we will extract the source archive.

tar xvf node-v6.3.1.tar.gz

And enter the source folder.

cd node-v6.3.1

Then we will need to install some packages in order to compile the source.

sudo yum install gcc gcc-c++

After all the dependencies are installed we ca now compile and install node.js.

./configure
make

When make is complete you can install node.js using the command.

make install

All is done! Now you can make your scalable network application in the fastest time possible thanks to node.js!

[1]: https://nodejs.org/download/

comments (1)

  • wileysegovia

    - 6 years ago

    What year is this tutorial from? Important because of version numbers, etc.