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.

Prerequisites

  • A server running Rocky Linux 8 on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Rocky Linux 8 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Install Node.js 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 -sL https://rpm.nodesource.com/setup_16.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:

v16.11.0

To verify the NPM version, run the following command:

npm -v

You should see the following output:

8.0.0

Step 3 – Install Node.js 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/v0.35.3/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 v16.11.0...
Downloading https://nodejs.org/dist/v16.11.0/node-v16.11.0-linux-x64.tar.xz...
######################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.11.0 (npm v8.0.0)
Creating default alias: default -> node (-> v16.11.0)

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 v14.18.0...
Downloading https://nodejs.org/dist/v14.18.0/node-v14.18.0-linux-x64.tar.xz...
######################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.18.0 (npm v6.14.15)

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

nvm ls

You should see the following output:

->     v14.18.0
       v16.11.0
default -> node (-> v16.11.0)
node -> stable (-> v16.11.0) (default)
stable -> 16.11 (-> v16.11.0) (default)

To set the default Node.js version, run:

nvm use 16.11.0

You should see the following output:

Now using node v16.11.0 (npm v8.0.0)

Step 4 – Install Node.js 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:24:13 ago on Tuesday 12 October 2021 02:31:13 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                  

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 started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server 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