How to Install Node.js on Rocky Linux 9 or 8

In this guide, we will demonstrate how to install Node.js on Rocky Linux 9 or 8, providing a step-by-step approach to ensure a smooth setup process. Node.js, a popular JavaScript runtime, is renowned for its efficiency and scalability, making it an ideal choice for developing server-side and networking applications. Here’s a quick overview of its key features:

  • Asynchronous and Event-Driven: Node.js’s non-blocking, event-driven architecture allows it to handle numerous simultaneous connections efficiently.
  • Fast Execution: Built on Google Chrome’s V8 JavaScript engine, Node.js executes code swiftly, enhancing performance.
  • Single Programming Language: It enables developers to write server-side scripts in JavaScript, offering a unified development experience.
  • Large Ecosystem: With access to a vast repository of libraries and tools in the npm (node package manager), Node.js simplifies development tasks.
  • Cross-Platform Support: Node.js runs on various operating systems, including Linux, Windows, and macOS, ensuring versatility.

To make the most of Node.js on Rocky Linux, it’s important to follow the installation steps carefully. This will not only simplify the process but also ensure that you’re ready to leverage Node.js’s full potential in your next development project. Stay tuned for the detailed instructions on installing Node.js on your Rocky Linux system.

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 RPM

Installing Node.js on Rocky Linux involves using NodeSource RPM for a tailored version. NodeSource repositories are dependable for obtaining specific versions of Node.js.

Here’s how to proceed with installations for different Node.js versions:

Node.js v21.x Installation

To install Node.js version 21.x on Rocky Linux, start by adding the NodeSource repository for version 21.x using the command:

sudo dnf install https://rpm.nodesource.com/pub_21.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y

Then, install Node.js ensuring the correct version is obtained from the NodeSource repository:

sudo dnf install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1

Node.js v20.x Installation

For Node.js version 20.x, the installation process remains similar. Add the NodeSource repository for version 20.x:

sudo dnf install https://rpm.nodesource.com/pub_20.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y

Then execute the Node.js installation command, targeting the newly added repository:

Node.js v18.x Installation

Installing Node.js version 18.x involves first adding the NodeSource repository for this version:

sudo dnf install https://rpm.nodesource.com/pub_18.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y

Follow this by installing Node.js from this specific repository:

sudo dnf install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1

Node.js v16.x Installation

To install Node.js version 16.x, begin by adding the NodeSource repository for version 16.x:

sudo dnf install https://rpm.nodesource.com/pub_16.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y

Complete the process with the Node.js installation command:

sudo dnf install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1

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- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | 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.
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.

Leave a Comment