Atlantic.Net Blog

How to Install Node.js and NPM on Rocky Linux 8

Node.js is a free, and open-source JavaScript runtime built on Chrome’s V8 JavaScript engine used to build scalable network applications. Generally, it is used on the back-end, but you can also use it as a full-stack and front-end solution. It is cross-platform, lightweight, and supports a non-blocking I/O model and event-driven architecture. Node.js allows you to develop complex and very scalable web applications easily.

In this post, we will show you how to install Node.js and NPM on RockyLinux 8.

Step 1 – Install Nodejs Using NodeSource Repository

By default, the latest version of Node.js is not available in the RockyLinux 8 default repo, so you can use the NodeSource repository to install the latest version of Node.js.

First, install the curl command utility using the following command:

dnf install curl -y

Next, add the NodeSource repository with the following command:

curl --silent --location https://rpm.nodesource.com/setup_18.x | bash -

Next, install the latest Node.js version with the following command:

dnf install nodejs

After the installation, verify the Node.js version with the following command:

node -v

You should see the following output:

v18.19.0

To verify the NPM version, run the following command:

npm -v

You should see the following output:

10.2.3

Step 2 – Install Nodejs Using NVM

You can also install Node.js using the Node Version Manager (NVM). NVM provides an easy way to install and manage multiple Node.js versions in the same system.

First, install NVM using the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

This will install NVM on your system and add the NVM path to the .bashrc file.

Next, activate the NVM system path using the following command:

source ~/.bashrc

To verify the NVM version, run:

nvm --version

You should see the following output:

0.35.3

To install the latest Node.js version, run:

nvm install node

You should see the following output:

Downloading and installing node v21.6.0...
Downloading https://nodejs.org/dist/v21.6.0/node-v21.6.0-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v21.6.0 (npm v10.2.4)

To install the latest stable Node.js version, run:

nvm install --lts

You should see the following output:

Installing latest LTS version.
Downloading and installing node v20.11.0...
Downloading https://nodejs.org/dist/v20.11.0/node-v20.11.0-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v20.11.0 (npm v10.2.4)

To list all Node.js versions installed in your system, run:

nvm ls

You should see the following output:

 v20.2.0
-> v20.11.0
v21.6.0
system
default -> 20.2.0 (-> v20.2.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v21.6.0) (default)
stable -> 21.6 (-> v21.6.0) (default)
lts/* -> lts/iron (-> v20.11.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.19.0 (-> N/A)
lts/iron -> v20.11.0
To set the default Node.js version, run:
nvm use 20.11.0

You should see the following output:

Now using node v20.11.0 (npm v10.2.4)

Step 3 – Install Nodejs Using Rocky Linux Repository

By default, Node.js is included in the Rocky Linux AppStream repository. You can list all available Node.js versions using the following command:

dnf module list nodejs

You should see the following output:

Last metadata expiration check: 0:13:39 ago on Thu 18 Jan 2024 02:32:57 PM UTC.
Rocky Linux 8 - AppStream
Name      Stream    Profiles                                Summary             
nodejs    10 [d]    common [d], development, minimal, s2i   Javascript runtime  
nodejs    12        common [d], development, minimal, s2i   Javascript runtime  
nodejs    14        common [d], development, minimal, s2i   Javascript runtime  
nodejs    16        common [d], development, minimal, s2i   Javascript runtime  
nodejs    18        common [d], development, minimal, s2i   Javascript runtime  
nodejs    20        common [d], development, minimal, s2i   Javascript runtime  

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

Now, install the Node.js version 14 using the following command:

dnf module install nodejs:14

To verify the Node.js version, run:

node -v

Sample output:

v14.17.5

To verify the NPM version, run:

npm -v

Sample output:

6.14.14

Conclusion

In the above guide, we explained three different ways to install Node.js and NPM on Rocky Linux 8. You can now install your required Node.js version using any of the above methods. Give it a try on your dedicated server from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year