November 24, 2020
How to install node.js on CentOS 8

How To Install Node.js version 14 On CentOS 8

On this article we will discuss how to install Node Js version 14.15 LTS on CentOS 8.

Introduction

Node.js is an open-source, a JavaScript runtime environment for server-side programming which enable executing JavaScript code outside a web browser. Node.js allows developers to create scalable backend functionality using JavaScript and producing dynamic web page content before the page is sent to the user’s web browser. Node.js interprets JavaScript using Google’s V8 JavaScript engine, developed by Ryan Dahl in 2009. NPM (Node Package Manager) is the default package manager for Node.js which helps developers share and reuse their code. On this article we will discuss how to install Node.js on CentOS 8.

Node.JS version

There are two versions of NodeJS available for users. When this article is being written, the latest version of Node.js is as follow (Check out the official page to find the latest) :

Node.js version : LTS & Current
  • v14.x (Long Term Supported)
  • v15.x (Current Latest Version)

On this article we will discuss how to install Node.js version 14 LTS on CentOS Linux Operating system.

Install Node.js 14.15 On CentOS 8

In CentOS 8, Node.js is available as default AppStream software repository and we just enabling one version we need among them for the appropriate module stream to be used. Due to Node.js version on our systen, and we found if the Node.js version 14 is not exist yet, so we have to add it repository first.

1. Inspecting Node.js version

Before installing Node.js version 14 LTS on our CentOS 8, first we will be Inspecting for Node.js version installed on our system. This step will be accomplished by submitting command line : rpm -qa 'node|npm' | grep -v nodesource

[ramans@otodiginet ~]$ rpm -qa 'node|npm' | grep -v nodesource
npm-6.14.4-1.10.21.0.3.module_el8.2.0+391+8da3adc6.x86_64
nodejs-full-i18n-10.21.0-3.module_el8.2.0+391+8da3adc6.x86_64
nodejs-10.21.0-3.module_el8.2.0+391+8da3adc6.x86_64
Node.js version

2. Removing Previous Node.js

It seems if our system appears to already have Node.js installed from an alternative source. We will remove it first by submitting command line sudo yum remove -y nodejs npm.

[ramans@otodiginet ~]$ sudo yum remove -y nodejs npm
[sudo] password for ramans:
Dependencies resolved.
Package Architecture Version Repository Size
Removing:
nodejs x86_64 1:10.21.0-3.module_el8.2.0+391+8da3adc6 @AppStream 30 M
npm x86_64 1:6.14.4-1.10.21.0.3.module_el8.2.0+391+8da3adc6 @AppStream 16 M
Node.js removing previous version

The output will be :

Removed:
mod_passenger-6.0.4-3.el8.x86_64
nodejs-1:10.21.0-3.module_el8.2.0+391+8da3adc6.x86_64
nodejs-full-i18n-1:10.21.0-3.module_el8.2.0+391+8da3adc6.x86_64
npm-1:6.14.4-1.10.21.0.3.module_el8.2.0+391+8da3adc6.x86_64
passenger-6.0.4-3.el8.x86_64
passenger-devel-6.0.4-3.el8.x86_64
rubygem-rack-2.2.2-1.el8.noarch
rubygem-rake-12.3.0-105.module_el8.1.0+214+9be47fd7.noarch

Complete!

Then we verify it again to ensure if the previous Node.js was removed by submitting command line : rpm -qa 'node|npm' | grep -v nodesource.

3. Downloading Node.js and setup RPM.

At this point we will add Node.js repostory version 14 repository to CentOS 8.

[ramans@otodiginet ~]$ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_14.x/el/8/x86_64/nodesource-release-el8-1.noarch.rpm'
Node.js q4.15 RPM installaton

4. Install Node.js Version 14 LTS

After repository was added, the we install Node.js by submitting command line : sudo dnf install -y nodejs.

[ramans@otodiginet ~]$ sudo dnf install -y nodejs
Node.js Packages for Enterprise Linux 8 - x86_64 48 kB/s | 560 kB 00:11
Last metadata expiration check: 0:00:08 ago on Fri 13 Nov 2020 08:26:01 PM PST.
Dependencies resolved.
Package Architecture Version Repository Size
Installing:
nodejs x86_64 2:14.15.0-1nodesource nodesource 32 M

Then we also install

development tools to build native addon by submitting command line : sudo yum install gcc-c++ make

[ramans@otodiginet ~]$ sudo dnf install gcc-c++ make
[sudo] password for ramans:
Last metadata expiration check: 0:10:08 ago on Fri 13 Nov 2020 08:26:01 PM PST.
Package gcc-c++-8.3.1-5.el8.0.2.x86_64 is already installed.
Package make-1:4.2.1-10.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.

5. Install yarn package

Then we install the yarn package, by submitting command line :

  1. Add yarn repository : curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
  2. Install yarn package : sudo dnf install yarn
[ramans@otodiginet ~]$ curl
 -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
[yarn]
name=Yarn Repository
baseurl=https://dl.yarnpkg.com/rpm/
enabled=1
gpgcheck=1
gpgkey=https://dl.yarnpkg.com/rpm/pubkey.gpg

[ramans@otodiginet ~]$ sudo dnf install yarn
Yarn Repository 15 kB/s | 365 kB 00:24
Last metadata expiration check: 0:00:11 ago on Fri 13 Nov 2020 08:37:25 PM PST.
Dependencies resolved.
Package Architecture Version Repository Size
Installing:
yarn noarch 1.22.5-1 yarn 1.2 M
Transaction Summary
Install 1 Package
Total download size: 1.2 M
Installed size: 5.1 M
Is this ok [y/N]: y
Downloading Packages:
[MIRROR] yarn-1.22.5-1.noarch.rpm: Curl error (35): SSL connect error for https://dl.yarnpkg.com/rpm/yarn-1.22.5-1.noarch.rpm [OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to dl.yarnpkg.com:443 ]
yarn-1.22.5-1.noarch.rpm 28 kB/s | 1.2 MB 00:42
Total 28 kB/s | 1.2 MB 00:42
warning: /var/cache/dnf/yarn-39eb54bf733530c3/packages/yarn-1.22.5-1.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 6963f07f: NOKEY
Yarn Repository 205 B/s | 1.6 kB 00:07
Importing GPG key 0x6963F07F:
Userid : "Yarn RPM Packaging yarn@dan.cx"
Fingerprint: 9A6F 73F3 4BEB 7473 4D8C 6914 9CBB B558 6963 F07F
From : https://dl.yarnpkg.com/rpm/pubkey.gpg
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : yarn-1.22.5-1.noarch 1/1
Verifying : yarn-1.22.5-1.noarch 1/1
Installed products updated.
Installed:
yarn-1.22.5-1.noarch
Complete!
install yarn package

6. Testing Node.js

So far, the Node.js installation was completed done. Then we will test the Node.js by creating a script to run as a web server. For this purpose, we will create a file called as demo_server.js

[ramans@otodiginet ~]$ vi demo_server.js

The following code inside a file :

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Bray');
}).listen(3003, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3003/');
Share this article via :

Leave a Reply

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