How to Install Node.js on Rocky Linux EL9 or EL8

Node.js has revolutionized how developers approach JavaScript, transitioning it from a mere client-side scripting language to a powerful tool for server-side applications and command-line utilities. If you plan to install Node.js on Rocky Linux 9 or the older stable Enterprise Linux release of Rocky Linux 8, this introduction will provide you with a comprehensive overview.

Node.js: Expanding JavaScript’s Horizons:

  • Server-Side Development: Node.js leverages its non-blocking, event-driven architecture to enable the crafting of efficient web servers and networking tools in JavaScript. Its design is particularly adept at handling data-intensive, real-time web applications.
  • Command-Line Utilities: With the npm package manager bundled in, Node.js facilitates the development of robust command-line tools, streamlining various development tasks.
  • Unified Development: Node.js allows for a cohesive development process, using JavaScript for client-side and server-side scripting.

Why Choose Node.js?:

  • Asynchronous Design: Node.js operates asynchronously, ensuring servers don’t stall waiting for APIs. This design enhances responsiveness and efficiency.
  • Scalability: Despite being single-threaded, Node.js’s event loop ensures high scalability, efficiently handling numerous simultaneous requests.
  • Cross-Platform: Node.js is versatile and deployable across Linux, macOS, and Windows, catering to a diverse user base.
  • Vibrant Ecosystem: The npm package manager enriches the Node.js environment with many open-source libraries, fostering innovation and collaboration.
  • V8 Engine: Powered by Google’s V8 JavaScript Engine, Node.js compiles JavaScript directly to machine code, ensuring optimal performance.

With the foundational knowledge, the subsequent guide will detail the steps to integrate Node.js into your Rocky Linux environment seamlessly. Whether you’re using Rocky Linux 9 or the older Rocky Linux 8, the guide will cover installation methods ranging from the default distribution version to the NodeSource RPM repositories and the versatile Node Version Manager (NVM) for managing multiple Node.js versions.

Install Node.js on Rocky Linux 9 or 8 via DNF Appstream

Step 1: Update Rocky Linux Before Node.js Installation

The initial stage of our installation process involves updating the existing Rocky Linux system. Regularly updating your system guarantees that all the installed software and utilities are at their most recent versions. This helps avoid potential software clashes and ensures the latest version of Node.js is installed. To update your system, execute the following command in your terminal:

sudo dnf upgrade --refresh

This command will fetch the newest versions of all packages and upgrade your system to the latest state. You are using sudo to execute the command with root privileges, dnf is the package manager used in Rocky Linux, upgrade is the operation that upgrades all outdated packages, and --refresh ensures that all repositories are refreshed before the operation.

Step 2: Install Node.js on Rocky Linux 9 or 8 via DNF Command

Now that your Rocky Linux system is up-to-date, it’s time to proceed with the Node.js installation. For this, we will leverage the repository with Rocky Linux. Utilizing the repository ensures an easy installation process and future updates. Run the following command to install Node.js:

sudo dnf install nodejs

In this command, sudo is for root privileges, dnf is the package manager, install is the operation to install a new package, and nodejs is the name of the package to be installed.

Step 3: Verifying Node.js Installation on Rocky Linux

With Node.js installed, verifying the installation is essential to ensure everything proceeded as expected. This step involves checking the installed Node.js version to confirm if the installation was successful. To verify your Node.js installation, execute the following command:

node --version

This command returns the installed Node.js version in your terminal. If the installation has gone smoothly, you’ll see the version number displayed, indicating that Node.js is correctly installed on your Rocky Linux system and is ready for use.

Install Node.js on Rocky Linux 9 or 8 via NodeSource

Choosing the correct version of Node.js for your projects can significantly influence your software’s compatibility and functionality. While the Rocky Linux repository provides a stable version of Node.js, you might need a more recent or a specific major version. This is where the NodeSource repository shines. It gives you access to the latest releases and lets you choose from different major versions of Node.js.

Step 1: Import NodeSource Repository on Rocky Linux

To leverage the advantages of NodeSource, we first need to integrate the repository into our system. This process requires downloading and executing a script that adds the NodeSource repository and updates your package list. You can specify the major version of Node.js that you prefer by replacing <version> in the following command:

curl -fsSL<version>.x | sudo 0E bash -

In this command, curl fetches the setup script from the NodeSource repository, -fsSL sets options for silent operation, following redirects, and error reporting, and sudo -E bash - executes the downloaded script with your environment variables, integrating the NodeSource repository into your system.

You can use the following examples for importing the current stable or long-term support (LTS) versions of Node.js:

Current stable version:

curl -fsSL | sudo -E bash -

Long-term support (LTS) version:

curl -fsSL | sudo -E bash -

If the curl command is not found, it signifies that the curl package is not installed on your system. To install it, use the following command:

Step 2: Install Node.js on Rocky Linux 9 or 8 via DNF Command

With the NodeSource repository now part of your system, you’re set to install Node.js. The NodeSource repository ensures you install the Node.js version you selected and any required dependencies. Execute the following command to install Node.js:

sudo dnf install nodejs

After the completion of the installation process, it’s crucial to verify that the Node.js installation has been successful and that the correct version is installed. This can be done by running the command:

node --version

This command returns the version of Node.js installed on your system, confirming the successful installation of the specified Node.js version.

Install Node.js on Rocky Linux 9 or 8 via Node Version Manager (NVM)

Installing Node.js using Node Version Manager (NVM) presents a sophisticated alternative that’s particularly handy when managing multiple Node.js versions for different projects. NVM’s capability to switch seamlessly between Node.js versions grants you an extra layer of flexibility that makes your development process smoother.

Step 1: Install NVM on Rocky Linux 9 or 8

The first stage in this process is installing NVM on your system. Depending on your preference or system configuration, you can use either curl or wget to fetch the NVM installation script:

curl -o- | bash


wget -qO- | bash

These commands will download the NVM installation script and execute it. Following a successful installation, you must restart your terminal or source your bashrc file. This action is essential to load NVM into your current shell session, making the nvm command available. To load NVM without restarting your terminal, execute:

source ~/.bashrc

Step 2: Install Node.js on Rocky Linux 9 or 8 via NVM

With NVM now available, you can manage multiple Node.js versions effectively, providing the flexibility needed when handling different projects.

2.1: List Available Node.js Versions on Rocky Linux via NVM

To begin, you might want to view the various Node.js versions accessible for installation. To do this, use the command:

nvm ls-remote

This command lists all available Node.js versions. This list can be beneficial when deciding the Node.js version that best suits your project requirements, such as the latest LTS release or a specific version number.

Screenshot illustrating the output of the 'nvm ls-remote' command on Rocky Linux.Pin
Sample screenshot of the list of Node.js versions available for installation using NVM on Rocky Linux.

2.2: Node.js Version Installation on Rocky Linux via NVM

Once you have determined the Node.js version you desire, use the following command to install it. Remember to replace <version> with the specific version number:

nvm install <version>

For example, if you wish to install Node.js version v20.2.0, execute the following:

nvm install 20.2.0

Executing this command downloads and installs the specified version of Node.js.

2.3: Verification of Node.js Installation on Rocky Linux via NVM

After installation, it’s always prudent to verify the version of Node.js that has been installed. This can be done with the command:

node --version

This command returns the version of Node.js that is currently active on your system, serving as a confirmation of successful installation.

2.4: Switching Between Node.js Versions on Rocky Linux via NVM

One of the fundamental benefits of NVM is the ease with which you can switch between different Node.js versions. To change your active Node.js version, use the following command, again replacing <version> with the specific version number:

nvm use <version>

For instance, if you wish to switch to Node.js version 18.16.0, execute the following:

nvm use 18.16.0

This command alters the active Node.js version for your current session. However, if you want a specific Node.js version to be the default in new terminal sessions, use the command:

nvm alias default <version>

Replace <version> with the desired version number. For example, to set Node.js version 18.16.0 as the default, execute:

nvm alias default 18.16.0

Additional Commands: Node.js Removal from Rocky Linux

This segment elucidates the process of uninstalling Node.js from a Rocky Linux system. The specific sequence of steps depends on the method initially employed to install Node.js—whether through the Rocky Linux repository, NodeSource, or NVM.

Remove Node.js From Rocky Linux 9 or 8 Installed via Appstream or NodeSource

Suppose Node.js was installed on your system via the Rocky Linux repository or NodeSource. In that case, the dnf program can be utilized to execute the uninstallation. The command to be executed is as follows:

sudo dnf remove nodejs

This command initiates the removal of Node.js, including its related configuration files. You will be asked to affirm the removal operation, and once you do, the uninstallation will proceed.

Remove Node.js From Rocky Linux 9 or 8 Installed via NVM

The uninstallation process is more detailed for systems where Node.js was installed using the Node Version Manager (NVM).

2.1: Ascertain Current Node.js Version

Firstly, it is crucial to ascertain the Node.js version currently installed on your system. This can be achieved with the following command:

nvm current

The execution of this command reveals the active Node.js version on your system.

2.2: Deactivate NVM on Rocky Linux

Before proceeding to uninstall Node.js, NVM must be deactivated. This ensures that the currently active version of Node.js is unloaded from your session. The command to execute this operation is:

nvm deactivate

2.3: Remove Node.js Version Using NVM on Rocky Linux

Having deactivated NVM, you can now proceed to uninstall the specific version of Node.js initially installed using NVM. Remember to replace <version> with the version number you wish to uninstall:

nvm uninstall <version>

For example, to uninstall Node.js version v20.2.0, execute the following:

nvm uninstall 20.2.0

This command effectuates the removal of the specified Node.js version from your system, thereby marking the completion of the uninstallation process.

Closing Thoughts

Throughout this piece, we’ve walked through the installation process for Node.js on the Rocky Linux platform, outlining the traditional repository method and the use of Node Version Manager (NVM). By leveraging NVM, you can manage multiple Node.js versions on your system—adding a significant degree of flexibility, especially when juggling different projects with varying dependencies. Moreover, we’ve also explained the process of uninstalling Node.js, catering to both traditional and NVM installations.

Understanding these steps and procedures deepens your grasp of the Node.js environment, bolstering your efficiency when dealing with diverse Node.js-related tasks. Notwithstanding, continuous exploration and learning will surely take your proficiency to even higher levels.

Share to...