How to install node.js on RHEL 8 / CentOS 8 Linux

Node.js is a Javascript runtime environment based on the V8 open source engine made by Google and originally used in Chrome. Thanks to Node.js we can run Javascript outside of the browser context, and use it also like a server-side scripting language, thus creating an entire web application around it. In this tutorial we will see how to install Node.js in the RHEL 8 / CentOS 8 distribution.

In this tutorial you will learn:

  • How to list the available Node.js versions on RHEL 8 / CentOS 8
  • How to install a specific version of Node.js
  • How to switch between Node.js versions on RHEL 8 / CentOS 8

node-logo

The Node.js – RHEL 8

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software The software needed to follow this tutorial is already included in a minimal installation of Rhel 8
Other Root privileges to install the needed packages
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Which version of Node.js ?

As we saw in a previous article about install php on Rhel8, the version of Red Hat Enterprise Linux introduces a new way of organizing software in repositories. By default there are only two software sources enabled in the distribution: BaseOs and Appstream. The former contains the core packages needed by the operating system, while the latter hosts various types of software organized in modules.

The main advantage of using this paradigm is that it’s possible to choose between different versions of the same application or utility. Node.js is one of the applications included in the Appstream repository, therefore to check the versions of this Javascript runtime available on RHEL 8, all we have to do is to use module, a subcommand of dnf, the distribution package manager. We run:



$ sudo dnf module list nodejs

The output of the command shows the available modules and their status:

Red Hat Enterprise Linux 8 for x86_64 - AppStream Beta (RPMs)
Name                       Stream                     Profiles                                      Summary
nodejs                     10 [d]                     development, minimal, s2i, default [d]        Javascript runtime
nodejs                     8                          development, minimal, s2i, default [d]        Javascript runtime

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

What does this output tell us? First of all we can see that there are two versions (or “streams”) of Node.js available on the system: 10, and 8. We can also see that the former is marked as [d]and therefore is set as the default one to be installed. For each stream, multiple profiles are available: different set of packages will be installed depending on which one is selected. To see the list of packages that would be installed with each profile, we can run the following command:

$ sudo dnf module info --profile nodejs

The syntax of the command is intuitive: we used dnf with the module subcommand and the info action, to request information about the nodejs module. By providing the --profile option, we specified that we want information about the available profiles. Here is the output of the command:

Name        : nodejs:10:20181011133319:9edba152:x86_64
development : nodejs
            : nodejs-devel
            : npm
minimal     : nodejs
s2i         : nodejs
            : nodejs-nodemon
            : npm
default     : nodejs
            : npm

Name        : nodejs:8:20181011134412:9edba152:x86_64
development : nodejs
            : nodejs-devel
            : npm
minimal     : nodejs
s2i         : nodejs
            : nodejs-nodemon
            : npm
default     : nodejs
            : npm

For each available stream the list of packages included in each profile is displayed. We can see that by using the default profile, the packages included in the installation are nodejs itself and npm, the Node Package Manager. By using the development profile, the nodejs-devel package is added to the list, while when using the minimal one, the only package installed is nodejs. Finally, the s2i (Source-to-Image) profile includes nodejs, npm, and nodejs-nodemon which is basically a script meant to be used during development of a node.js app.

Installing the default version

Now that we know the available Node.js versions, we can decide which one to install. As we said above, the default versions is 10. If this is the desired one, all we have to do is to run:

$ sudo dnf install nodejs

A summary of the packages to be installed and their dependencies will be displayed on the terminal, and the system will ask for the confirmation to proceed:

======================================================================================================================================================
 Package                 Arch               Version                                          Repository                                         Size
======================================================================================================================================================
Installing:
 nodejs                  x86_64             1:10.11.0-2.el8+2021+27085a9b                    Rhel-8-for-x86_64-appstream-beta-rpms             8.4 M
Installing dependencies:
 npm                     x86_64             1:6.4.1-1.10.11.0.2.el8+2021+27085a9b            Rhel-8-for-x86_64-appstream-beta-rpms             3.6 M
 libuv                   x86_64             1:1.23.1-1.el8                                   Rhel-8-for-x86_64-appstream-beta-rpms             134 k
 http-parser             x86_64             2.8.0-1.el8                                      Rhel-8-for-x86_64-appstream-beta-rpms              40 k
Enabling module streams:
 nodejs                                     10


Transaction Summary
======================================================================================================================================================
Install  4 Packages

Total download size: 12 M
Installed size: 57 M
Is this ok [y/N]:

Specifying the version to install

What if we want to install an alternative version (a stream in the Rhel terminology) or a different profile ? The syntax is quite simple:



name:stream/profile

Basically, to install the default version of the nodejs module, but with the development profile, we would run:

$ sudo dnf module install nodejs:10/development

The list of packages that would be installed increases accordingly to the change of profile:

======================================================================================================================================================
 Package                       Arch            Version                                          Repository                                      Size
======================================================================================================================================================
Installing group/module packages:
 npm                           x86_64          1:6.4.1-1.10.11.0.2.el8+2021+27085a9b            Rhel-8-for-x86_64-appstream-beta-rpms          3.6 M
 nodejs-devel                  x86_64          1:10.11.0-2.el8+2021+27085a9b                    Rhel-8-for-x86_64-appstream-beta-rpms           11 M
 nodejs                        x86_64          1:10.11.0-2.el8+2021+27085a9b                    Rhel-8-for-x86_64-appstream-beta-rpms          8.4 M
Installing dependencies:
 redhat-rpm-config             noarch          115-1.el8                                        Rhel-8-for-x86_64-appstream-beta-rpms           82 k
 perl-srpm-macros              noarch          1-25.el8                                         Rhel-8-for-x86_64-appstream-beta-rpms           11 k
 go-srpm-macros                noarch          2-16.el8                                         Rhel-8-for-x86_64-appstream-beta-rpms           14 k
 dwz                           x86_64          0.12-9.el8                                       Rhel-8-for-x86_64-appstream-beta-rpms          109 k
 libuv                         x86_64          1:1.23.1-1.el8                                   Rhel-8-for-x86_64-appstream-beta-rpms          134 k
 http-parser                   x86_64          2.8.0-1.el8                                      Rhel-8-for-x86_64-appstream-beta-rpms           40 k
 python3-rpm-macros            noarch          3-35.el8                                         Rhel-8-for-x86_64-appstream-beta-rpms           13 k
 rust-srpm-macros              noarch          5-2.el8                                          Rhel-8-for-x86_64-appstream-beta-rpms          9.3 k
 ocaml-srpm-macros             noarch          5-4.el8                                          Rhel-8-for-x86_64-appstream-beta-rpms          9.5 k
 efi-srpm-macros               noarch          3-2.el8                                          Rhel-8-for-x86_64-appstream-beta-rpms           22 k
 qt5-srpm-macros               noarch          5.11.1-2.el8                                     Rhel-8-for-x86_64-appstream-beta-rpms           11 k
 http-parser-devel             x86_64          2.8.0-1.el8                                      Rhel-8-for-x86_64-appstream-beta-rpms           18 k
 nodejs-packaging              noarch          17-2.el8+1541+81a6effd                           Rhel-8-for-x86_64-appstream-beta-rpms           19 k
 libuv-devel                   x86_64          1:1.23.1-1.el8                                   Rhel-8-for-x86_64-appstream-beta-rpms           34 k
 ghc-srpm-macros               noarch          1.4.2-7.el8                                      Rhel-8-for-x86_64-appstream-beta-rpms          9.4 k
 python-srpm-macros            noarch          3-35.el8                                         Rhel-8-for-x86_64-appstream-beta-rpms           14 k
 openblas-srpm-macros          noarch          2-2.el8                                          Rhel-8-for-x86_64-appstream-beta-rpms          8.0 k
 krb5-devel                    x86_64          1.16.1-19.el8                                    Rhel-8-for-x86_64-baseos-beta-rpms             546 k
 libsepol-devel                x86_64          2.8-1.el8                                        Rhel-8-for-x86_64-baseos-beta-rpms              85 k
 libcom_err-devel              x86_64          1.44.3-1.el8                                     Rhel-8-for-x86_64-baseos-beta-rpms              37 k
 pcre2-devel                   x86_64          10.31-11.el8                                     Rhel-8-for-x86_64-baseos-beta-rpms             591 k
 zip                           x86_64          3.0-21.el8                                       Rhel-8-for-x86_64-baseos-beta-rpms             270 k
 libkadm5                      x86_64          1.16.1-19.el8                                    Rhel-8-for-x86_64-baseos-beta-rpms             184 k
 unzip                         x86_64          6.0-38.el8                                       Rhel-8-for-x86_64-baseos-beta-rpms             192 k
 keyutils-libs-devel           x86_64          1.5.10-6.el8                                     Rhel-8-for-x86_64-baseos-beta-rpms              48 k
 openssl-devel                 x86_64          1:1.1.1-6.el8                                    Rhel-8-for-x86_64-baseos-beta-rpms             2.3 M
 libselinux-devel              x86_64          2.8-5.el8                                        Rhel-8-for-x86_64-baseos-beta-rpms             199 k
 zlib-devel                    x86_64          1.2.11-10.el8                                    Rhel-8-for-x86_64-baseos-beta-rpms              56 k
 pcre2-utf16                   x86_64          10.31-11.el8                                     Rhel-8-for-x86_64-baseos-beta-rpms             223 k
 libverto-devel                x86_64          0.3.0-5.el8                                      Rhel-8-for-x86_64-baseos-beta-rpms              18 k
 pcre2-utf32                   x86_64          10.31-11.el8                                     Rhel-8-for-x86_64-baseos-beta-rpms             215 k
Installing module profiles:
 nodejs/development

Enabling module streams:
 nodejs                                        10


Transaction Summary
======================================================================================================================================================
Install  34 Packages

In the same fashion, to install version 8 of the Javascript runtime with the default profile, we would run:

$ sudo dnf module install nodejs:8

In this case, since we wanted to use the default profile, we omitted to include it in the command. As you can
verify in the output below, the version of the packages to be installed changed again:

======================================================================================================================================================
 Package                 Arch               Version                                          Repository                                         Size
======================================================================================================================================================
Installing group/module packages:
 nodejs                  x86_64             1:8.11.4-2.el8+2022+2ec55091                     Rhel-8-for-x86_64-appstream-beta-rpms             7.5 M
 npm                     x86_64             1:5.6.0-1.8.11.4.2.el8+2022+2ec55091             Rhel-8-for-x86_64-appstream-beta-rpms             4.1 M
Installing dependencies:
 libuv                   x86_64             1:1.23.1-1.el8                                   Rhel-8-for-x86_64-appstream-beta-rpms             134 k
 http-parser             x86_64             2.8.0-1.el8                                      Rhel-8-for-x86_64-appstream-beta-rpms              40 k
Installing module profiles:
 nodejs/default

Enabling module streams:
 nodejs                                     8


Transaction Summary
======================================================================================================================================================
Install  4 Packages

Suppose we confirmed the installation of the list of packages above. If we now run:

$ sudo dnf module list nodejs

We can see the changes reflected by the notation used in the output:

Name                      Stream                    Profiles                    Summary
nodejs                    10 [d]                    development, minimal, s2i, default [d]                       Javascript runtime
nodejs                    8 [e]                     development, minimal, s2i, default [d] [i]                   Javascript runtime

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled


The version 10 is still marked as the default one, but now the version 8 stream is marked with [e] which means that it has been automatically enabled. Furthermore, the [i] mark is used in the profiles section of the same stream, near the name of the installed one.

Switching version

What if we installed a specific version of Node.js and we want to change to another one? Basically, we have to specify the new version to install and the system will take care of the rest. For example, to switch back to version 10 we run again:

$ sudo dnf module install nodejs:10/default

The actions that would be performed in order to satisfy the request are calculated and displayed to us. In the Transaction Summary section of the output below, we can indeed notice that 2 packages (nodejs and npm) would be upgraded:

======================================================================================================================================================
 Package             Arch                Version                                             Repository                                          Size
======================================================================================================================================================
Upgrading:
 npm                 x86_64              1:6.4.1-1.10.11.0.2.el8+2021+27085a9b               Rhel-8-for-x86_64-appstream-beta-rpms              3.6 M
 nodejs              x86_64              1:10.11.0-2.el8+2021+27085a9b                       Rhel-8-for-x86_64-appstream-beta-rpms              8.4 M
Switching module streams:
 nodejs                                  8 -> 10


Transaction Summary
======================================================================================================================================================
Upgrade  2 Packages

Conclusions

Node.js is a runtime based on the V8 Javascript engine made by google, and originally used in the Chrome browser. By using it we can create applications using Javascript outside the context of a web browser. In this tutorial we saw how to install the nodejs package on RHEL/CentOS Linux 8 Operating system, what versions of the package are available in the default repositories, how is possible to install a specific one, and how, thanks to modules, the new way of organizing software in the latest version of the Red Hat enterprise distribution, we can switch from one version to the other.