You are here:

Set up CentOS 7 with Node.js

Set up CentOS 7 with Node.js

Overview

What is node.js?

Node.js is a platform built on Chrome’s JavaScript runtime, designed for effortlessly constructing fast and scalable network applications. Utilizing an event-driven, non-blocking I/O model, Node.js is lightweight and efficient, making it particularly well-suited for data-intensive real-time applications that operate across distributed devices.

Requirements

To ensure a successful CSF (ConfigServer Security & Firewall) setup, make sure you have the following prerequisites:

  1. A CentOS 7 x64 VPS server.
  2. Root access to the server.
  3. An SSH client (Download Putty[1] or Bitvise[2] based on your operating system and preference).

Once you have these prerequisites in place, you can proceed with the CSF setup. Follow the guide carefully, and feel free to use copy and paste for the commands provided to streamline the installation and configuration process.

Setting up Node.js on NVM

NVM, or Node Version Manager, is a software tool that facilitates the installation and management of multiple independent versions of Node.js and their associated node packages.

Before installing Node.js on your machine, you need to download and install NVM from GitHub. You can achieve this using the following command:

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

This command will install NVM version 0.13.1. However, to utilize NVM, we need to first configure our bash profile.

source ~/.bash_profile

After configuring the bash profile, you can run the command nvm to obtain a list of available Node.js versions 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 specific Node.js version by typing nvm install followed by the version you need. For example:

nvm install v6.3.1

To install another Node.js version, repeat the above commands with a different version specified at the end.

You can view the list of installed versions 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 specific Node.js version as the default, you can execute:

nvm alias default v6.3.1

The corresponding result should be:

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

Using the Epel Repository to install node.js

An alternative method of installing Node.js is from the Epel Repository, which is available for CentOS and other Linux distributions. To access the repository, you must first install the epel-release package by using the following command:

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

Using Source to Install Node.js

To acquire Node.js through manual compilation, you can obtain the source code from the project’s website. Visit the downloads page[1], right-click on the “Source Code” link, and select “Copy link address” or the equivalent option provided by your browser.

As of the latest release, Node.js is at version 6.3.1. You can download this version using the wget command.

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

Next, we’ll extract the archive of the source.

tar xvf node-v6.3.1.tar.gz

Afterward, open the source folder.

cd node-v6.3.1

Then, in order to compile the source, we must install a few packages.

sudo yum install gcc gcc-c++

We are now able to compile and install Node.js after installing all of the dependencies.

./configure
make

Once make has finished, use this command to install node.js.

make install

That’s it! Thanks to node.js, you can now create your scalable network application as quickly as possible!

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

Was this article helpful?
Dislike 0