How to Install NodeJS in Linux CentOS 8 virtual server

Posted on

This is an article for showing how to install NodeJS in Linux CentOS 8 operating system in a virtual server. The virtual server is running in a VirtualBox application. This is an important step before the virtual server has the ability to execute a NodeJS script. Actually, this article is referring another article with the title of ‘How To Install Latest Nodejs on CentOS/RHEL 8’ in this link. So, the following are the steps for installing NodeJS utility :

1. First of all, try to access the virtual server which is running in the VirtualBox application. The most simple way is to directly login to the virtual server. The other way is by accessing the virtual server remotely using SSH connection. Read the article with the title of ‘How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH’ in this link for further reference.

[root@10 ~]# dnf install -y gcc-c++ make
CentOS-8 - AppStream                                                                                                                        758  B/s | 4.3 kB     00:05
CentOS-8 - AppStream                                                                                                                        850 kB/s | 6.3 MB     00:07
CentOS-8 - Base                                                                                                                             6.4 kB/s | 3.9 kB     00:00
CentOS-8 - Base                                                                                                                             646 kB/s | 2.3 MB     00:03
CentOS-8 - Extras                                                                                                                           2.7 kB/s | 1.5 kB     00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                                      6.4 kB/s | 9.2 kB     00:01
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                                      227 kB/s | 536 kB     00:02
Extra Packages for Enterprise Linux 8 - x86_64                                                                                               47 kB/s | 5.7 kB     00:00
Extra Packages for Enterprise Linux 8 - x86_64                                                                                              901 kB/s | 8.8 MB     00:10
Last metadata expiration check: 0:00:01 ago on Thu 04 Feb 2021 12:37:53 PM EST.
Package make-1:4.2.1-10.el8.x86_64 is already installed.
Dependencies resolved.
============================================================================================================================================================================ Package                                      Architecture                        Version                                      Repository                              Size
============================================================================================================================================================================Installing:
 gcc-c++                                      x86_64                              8.3.1-5.1.el8                                AppStream                               12 M
Upgrading:
 libstdc++                                    x86_64                              8.3.1-5.1.el8                                BaseOS                                 451 k
Installing dependencies:
 libstdc++-devel                              x86_64                              8.3.1-5.1.el8                                AppStream                              2.0 M

Transaction Summary
============================================================================================================================================================================Install  2 Packages
Upgrade  1 Package

Total download size: 15 M
Downloading Packages:
(1/3): libstdc++-8.3.1-5.1.el8.x86_64.rpm                                                                                                   339 kB/s | 451 kB     00:01
(2/3): libstdc++-devel-8.3.1-5.1.el8.x86_64.rpm                                                                                             371 kB/s | 2.0 MB     00:05
(3/3): gcc-c++-8.3.1-5.1.el8.x86_64.rpm                                                                                                     934 kB/s |  12 MB     00:13
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total                                                                                                                                       1.0 MB/s |  15 MB     00:14
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                    1/1
  Upgrading        : libstdc++-8.3.1-5.1.el8.x86_64                                                                                                                     1/4
  Running scriptlet: libstdc++-8.3.1-5.1.el8.x86_64                                                                                                                     1/4
  Installing       : libstdc++-devel-8.3.1-5.1.el8.x86_64                                                                                                               2/4
  Installing       : gcc-c++-8.3.1-5.1.el8.x86_64                                                                                                                       3/4
  Cleanup          : libstdc++-8.3.1-5.el8.0.2.x86_64                                                                                                                   4/4
  Running scriptlet: libstdc++-8.3.1-5.el8.0.2.x86_64                                                                                                                   4/4
  Verifying        : gcc-c++-8.3.1-5.1.el8.x86_64                                                                                                                       1/4
  Verifying        : libstdc++-devel-8.3.1-5.1.el8.x86_64                                                                                                               2/4
  Verifying        : libstdc++-8.3.1-5.1.el8.x86_64                                                                                                                     3/4
  Verifying        : libstdc++-8.3.1-5.el8.0.2.x86_64                                                                                                                   4/4

Upgraded:
  libstdc++-8.3.1-5.1.el8.x86_64

Installed:
  gcc-c++-8.3.1-5.1.el8.x86_64                                                     libstdc++-devel-8.3.1-5.1.el8.x86_64

Complete!
[root@10 ~]# 

2. After executing the above command for preparing the requirements before installing the actual NodeJS package, execute the following command. The following command is a command to install a NodeJS repository in the operating system :

[root@10 ~]# curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -

## Installing the NodeSource Node.js 14.x repo...


## Inspecting system...

+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m

## Confirming "el8-x86_64" is supported...

+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_14.x/el/8/x86_64/nodesource-release-el8-1.noarch.rpm'

## As yum will try to install Node.js from the AppStream repository
instead of the NodeSource repository, the AppStream's version of Node.js has to be disabled.
## Run `sudo yum module enable -y nodejs` to reactivate the AppStream's Node.js repository.

+ yum module disable -y nodejs
Last metadata expiration check: 0:08:05 ago on Thu 04 Feb 2021 12:38:14 PM EST.
Dependencies resolved.
============================================================================================================================================================================================================================================
 Package                                                  Architecture                                            Version                                                    Repository                                                Size
============================================================================================================================================================================================================================================
Disabling modules:
 nodejs

Transaction Summary
============================================================================================================================================================================================================================================

Complete!

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.dQ0aN11IDj' 'https://rpm.nodesource.com/pub_14.x/el/8/x86_64/nodesource-release-el8-1.noarch.rpm'

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.dQ0aN11IDj'

## Cleaning up...

+ rm -f '/tmp/tmp.dQ0aN11IDj'

## Checking for existing installations...

+ rpm -qa 'node|npm' | grep -v nodesource

## Run `sudo yum install -y nodejs` to install Node.js 14.x and npm.
## You may also need development tools to build native addons:
     sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
     sudo yum install yarn

[root@10 ~]#

3. Next step, it is the actual process for installing NodeJS package. The command pattern is ‘dnf install nodejs’. Just execute the following command :

[root@10 ~]$ dnf install nodejs
Node.js Packages for Enterprise Linux 8 - x86_64                                                                                                                                                            285 kB/s | 686 kB     00:02
Dependencies resolved.
============================================================================================================================================================================================================================================
 Package                                             Architecture                                        Version                                                              Repository                                               Size
============================================================================================================================================================================================================================================
Installing:
 nodejs                                              x86_64                                              2:14.15.4-1nodesource                                                nodesource                                               32 M

Transaction Summary
============================================================================================================================================================================================================================================
Install  1 Package

Total download size: 32 M
Installed size: 91 M
Is this ok [y/N]: y
Downloading Packages:
nodejs-14.15.4-1nodesource.x86_64.rpm                                                                                                                                                                       939 kB/s |  32 MB     00:34
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                       939 kB/s |  32 MB     00:34
warning: /var/cache/dnf/nodesource-6e5a049480aa85b9/packages/nodejs-14.15.4-1nodesource.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 34fa74dd: NOKEY
Node.js Packages for Enterprise Linux 8 - x86_64                                                                                                                                                            1.6 MB/s | 1.6 kB     00:00
Importing GPG key 0x34FA74DD:
 Userid     : "NodeSource <gpg-rpm@nodesource.com>"
 Fingerprint: 2E55 207A 95D9 944B 0CC9 3261 5DDB E8D4 34FA 74DD
 From       : /etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
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
  Running scriptlet: nodejs-2:14.15.4-1nodesource.x86_64                                                                                                                                                                                1/1
  Installing       : nodejs-2:14.15.4-1nodesource.x86_64                                                                                                                                                                                1/1
  Running scriptlet: nodejs-2:14.15.4-1nodesource.x86_64                                                                                                                                                                                1/1
  Verifying        : nodejs-2:14.15.4-1nodesource.x86_64                                                                                                                                                                                1/1

Installed:
  nodejs-2:14.15.4-1nodesource.x86_64

Complete!
[root@10 ~]$
  1. Last but not least, do not forget to execute the following command in the command line interface to check the NodeJS version :
[root@10 ~]$ node -v
v14.15.4
[root@10 ~]$ npm -v
6.14.10
[root@10 ~]$

The above command execution is just to test whether the ‘node’ and ‘npm’ command is available. It is a parameter for checking the success of the NodeJS installation. Since the above command is producing an output showing the version of ‘node’ and also ‘npm’ with the ‘-v’ additional argument, the installation of the NodeJS is a success.


One thought on “How to Install NodeJS in Linux CentOS 8 virtual server

Leave a Reply