How to Install Node.js on Rocky Linux

Node.js provides a JavaScript runtime for building server-side applications, APIs, and command-line tools. Whether you are developing web applications, building microservices, or creating automation scripts, Node.js offers an event-driven, non-blocking I/O model that handles concurrent connections efficiently. By the end of this guide, you will have a working Node.js installation on Rocky Linux with npm (Node Package Manager) ready for development.

Node.js is not installed by default on Rocky Linux, so you will choose one of the methods below based on how you want to manage versions and updates.

Choose Your Node.js Installation Method

Rocky Linux offers several ways to install Node.js, each suited to different workflows and requirements. The following table compares the available methods to help you choose the approach that fits your needs.

MethodChannelVersionUpdatesBest For
DNF AppStreamRocky ReposDistribution default (v22 on EL10, modules on EL8/9)Automatic via dnf upgradeProduction servers needing stability and distro support
NodeSource RPMNodeSource GitHubLatest LTS or currentAutomatic via dnf upgradeDevelopers needing newer Node.js versions than AppStream provides
Node Version Manager (NVM)NVM GitHubAny Node.js versionManual via nvm installDevelopers managing multiple Node.js versions per project

For most users, the DNF AppStream method is recommended because it provides stable, tested packages that integrate with Rocky Linux’s security updates. Choose NodeSource if you need a specific Node.js version not available in AppStream, or NVM if you regularly switch between different Node.js versions for different projects.

These instructions apply to Rocky Linux 8, 9, and 10. Rocky Linux 8 and 9 use DNF module streams to offer multiple Node.js versions, while Rocky Linux 10 removed modularity and ships a single Node.js package version in AppStream. The differences are noted in each section.

Install Node.js via DNF AppStream

The AppStream repository includes Node.js packages tested and maintained by the Rocky Linux team. This method provides the simplest installation path and integrates with your system’s standard update process.

Update Your System

Before installing new packages, refresh the package cache and apply any pending updates. This ensures you install the latest available versions and avoid dependency conflicts.

sudo dnf upgrade --refresh

Rocky Linux 10: Install Node.js Directly

Rocky Linux 10 removed DNF modularity, so Node.js installs directly without module stream selection. The default AppStream package provides Node.js 22, a maintenance LTS release with support through April 2027. On Rocky 10, the npm CLI comes from the nodejs-npm package, which is pulled in as a weak dependency when you install nodejs.

sudo dnf install nodejs

After installation completes, verify that Node.js and npm are accessible:

node --version
npm --version

The output confirms the installed versions:

v22.19.0
10.9.3

Rocky Linux 8 and 9: Enable a Module Stream

Rocky Linux 8 and 9 use DNF module streams to offer multiple Node.js versions simultaneously. First, check which streams are available on your system:

dnf module list nodejs

On Rocky Linux 9, the output shows the available module streams:

Rocky Linux 9 - AppStream
Name   Stream Profiles                              Summary
nodejs 18     common [d], development, minimal, s2i Javascript runtime
nodejs 20     common [d], development, minimal, s2i Javascript runtime
nodejs 22     common [d], development, minimal, s2i Javascript runtime
nodejs 24     common [d], development, minimal, s2i Javascript runtime

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

For new development, enable the Node.js 24 stream for the current LTS line. If you need broader compatibility with older tooling or want to mirror Rocky Linux 10’s AppStream version, use the Node.js 22 stream instead.

On Rocky Linux 8, similar streams are available, but the default stream is Node.js 10 which reached end-of-life in April 2021. Enable the Node.js 24 stream for the latest LTS release (or choose 22 for compatibility):

sudo dnf module enable nodejs:24

With the stream enabled, install Node.js and npm together. On Rocky Linux 8 and 9, npm is a separate package and must be installed explicitly:

sudo dnf install nodejs npm

Verify the installation succeeded:

node --version
npm --version

Expected output on Rocky Linux 9 with the nodejs:24 stream:

v24.11.1
11.6.2

Understanding Node.js Module Streams

DNF module streams allow Rocky Linux 8 and 9 to ship multiple major versions of software like Node.js without conflicts. Each stream corresponds to a major Node.js release line. When you enable a stream, subsequent dnf install nodejs commands pull packages from that stream until you explicitly switch or reset it. Note that unlike Rocky Linux 10, the npm package manager is packaged separately on these versions and must be installed alongside Node.js.

The following table summarizes the Node.js LTS schedule to help you choose an appropriate stream:

VersionCodenameLTS StartEnd of LifeStatus
Node.js 20IronOctober 2023April 2026Maintenance LTS
Node.js 22JodOctober 2024April 2027Maintenance LTS
Node.js 24KryptonOctober 2025April 2028Active LTS (Recommended)

For new projects, Node.js 24 provides the best balance of modern features and long-term support. Node.js 22 remains a solid choice for projects that need broader ecosystem compatibility, and Rocky Linux 10’s AppStream currently ships Node.js 22 only. Existing projects with older dependencies may need Node.js 20, which receives security fixes until April 2026. For detailed lifecycle information, see the official Node.js release schedule.

Install Node.js via NodeSource RPM

NodeSource maintains Node.js RPM packages that often include newer versions than the distribution repositories. This method is useful when you need a specific Node.js version or faster access to new releases.

NodeSource packages install to the same paths as distribution packages. If you have Node.js from AppStream installed, remove it first to avoid conflicts: Rocky Linux 10 uses sudo dnf remove nodejs nodejs-npm, while Rocky Linux 8 and 9 use sudo dnf remove nodejs npm.

Add the NodeSource Repository

The setup script uses curl. Most Rocky installs include it already (Rocky 9 minimal uses curl-minimal), but if the command is missing install the package that matches your release.

Rocky Linux 8 and 10:

sudo dnf install curl -y

Rocky Linux 9 minimal images:

sudo dnf install curl-minimal -y

NodeSource provides setup scripts that configure the repository and GPG keys for your system. Choose the script matching your desired Node.js major version. The following example adds the Node.js 24.x repository:

curl -fsSL https://rpm.nodesource.com/setup_24.x | sudo bash -

NodeSource offers setup scripts for several active Node.js versions:

  • setup_24.x – Node.js 24 (Active LTS, latest features, recommended for new projects)
  • setup_22.x – Node.js 22 (Maintenance LTS, stable and widely compatible)
  • setup_20.x – Node.js 20 (Maintenance LTS, for compatibility with older dependencies)

The setup script adds the repository configuration to /etc/yum.repos.d/ and imports the NodeSource GPG signing key.

Install Node.js from NodeSource

With the repository configured, install Node.js using dnf:

sudo dnf install nodejs -y

Verify the installation by checking the installed versions:

node --version
npm --version

The output confirms NodeSource’s version is installed:

v24.12.0
11.6.2

Install Node.js via Node Version Manager (NVM)

NVM (Node Version Manager) installs Node.js in your home directory and allows you to switch between different versions instantly. This approach is particularly useful for developers working on multiple projects with different Node.js requirements, or when you need to test against several Node.js versions.

Install NVM

NVM relies on curl and a shell profile file. If curl is missing, install it with the package that matches your release.

Rocky Linux 8 and 10:

sudo dnf install curl -y

Rocky Linux 9 minimal images:

sudo dnf install curl-minimal -y

If you do not have a shell profile yet (common on minimal installs), create one so the installer can append its initialization lines:

touch ~/.bashrc

Download and run the NVM installation script. The following command uses the GitHub API to detect the latest release automatically, so you always install the current version:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$(curl -fsSL https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep -oE '"tag_name": "[^"]+"' | head -n 1 | cut -d'"' -f4)/install.sh | bash

The script clones NVM to ~/.nvm and appends initialization lines to your ~/.bashrc file. These lines are permanent and load NVM automatically in every new terminal session. To use NVM in your current terminal without closing it, reload the configuration file:

source ~/.bashrc

This command re-reads your shell configuration and makes nvm available immediately. Alternatively, open a new terminal window for the changes to load automatically. You only need to run this once after installation; future terminal sessions will load NVM automatically. If you use zsh instead of bash, run source ~/.zshrc instead.

If the automated version detection fails or you prefer to install a specific NVM version, check the NVM releases page for the latest version and use: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

Verify NVM is available by checking its version:

nvm --version
0.40.3

List Available Node.js Versions

NVM can install any Node.js version ever released. To see available LTS versions, run:

nvm ls-remote --lts

The output lists all LTS releases with their codenames. Here are the most recent entries:

       v22.20.0   (LTS: Jod)
       v22.21.0   (LTS: Jod)
       v22.21.1   (Latest LTS: Jod)
       v24.11.0   (LTS: Krypton)
       v24.11.1   (LTS: Krypton)
       v24.12.0   (Latest LTS: Krypton)

To see all versions including non-LTS releases, run nvm ls-remote without the --lts flag.

Install a Node.js Version

Install the latest LTS version with a single command:

nvm install --lts

NVM downloads the binary, extracts it to ~/.nvm/versions/, and activates it for your current session:

Installing latest LTS version.
Downloading and installing node v24.12.0...
Downloading https://nodejs.org/dist/v24.12.0/node-v24.12.0-linux-x64.tar.gz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v24.12.0 (npm v11.6.2)
Creating default alias: default -> lts/* (-> v24.12.0 *)

To install a specific version, provide the version number:

nvm install 22.21.1

After installing a specific version, verify it is active:

node --version
npm --version
v22.21.1
10.9.4

Switch Between Node.js Versions

If you have multiple Node.js versions installed via NVM, switch between them using the use command:

nvm use 22.21.1

To set a default version that activates in every new terminal session:

nvm alias default 22.21.1

View all installed versions and see which is currently active:

nvm ls

The output lists installed versions (marked with *) and the active aliases NVM will use in new shells:

       v22.21.1 *
       v24.12.0 *
default -> 22.21.1 (-> v22.21.1 *)
node -> stable (-> v24.12.0 *) (default)
stable -> 24.12 (-> v24.12.0 *) (default)
lts/* -> lts/krypton (-> v24.12.0 *)
lts/jod -> v22.21.1 *
lts/krypton -> v24.12.0 *

Troubleshoot Common Node.js Issues

Module Stream Conflicts on Rocky Linux 8 or 9

If you encounter errors when trying to enable a different Node.js module stream, you may need to reset the current stream first:

sudo dnf module reset nodejs
sudo dnf module enable nodejs:24

If you need the Node.js 22 stream instead, replace 24 with 22 in the enable command.

curl Conflicts on Rocky Linux 9 Minimal

Rocky Linux 9 minimal images ship curl-minimal, so dnf install curl can fail with a conflict. Use the minimal package instead, which still provides the curl command:

sudo dnf install curl-minimal -y

npm: command not found on Rocky Linux 8 or 9

If you installed Node.js on Rocky Linux 8 or 9 using module streams but the npm command is not found, the npm package was not installed. Unlike Rocky Linux 10 where npm is a weak dependency of Node.js, older Rocky versions package npm separately. Install it with:

sudo dnf install npm

After installation, verify npm is accessible:

npm --version
11.6.2

If you enabled the nodejs:22 stream, expect a 10.x npm version instead.

npm Permission Errors

When installing global npm packages without sudo, you may see permission errors. This happens because npm tries to write to system directories. Instead of using sudo with npm, configure npm to use a directory in your home folder:

mkdir -p ~/.npm-global
npm config set prefix "$HOME/.npm-global"
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Alternatively, open a new terminal window for the PATH change to load automatically.

Confirm npm is using the new prefix:

npm config get prefix
/home/rocky/.npm-global

After this change, globally installed npm packages go to ~/.npm-global without requiring elevated permissions.

Node.js Not Found After NVM Installation

If the node command is not found after installing via NVM, your shell configuration may not be loading NVM. Verify the NVM initialization lines exist in your ~/.bashrc:

grep NVM ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

The output should include the NVM_DIR export and source lines. If missing, add them manually or re-run the NVM installation script.

npm Install Fails with Git Errors

Some npm packages install dependencies directly from Git repositories. If you encounter errors during npm install mentioning git, install Git on Rocky Linux to resolve them.

Remove Node.js from Rocky Linux

The removal process depends on how you originally installed Node.js. Follow the section matching your installation method.

Remove Node.js Installed via DNF

Use the removal command that matches your AppStream version or repository source:

Rocky Linux 10 AppStream:

sudo dnf remove nodejs nodejs-npm

Rocky Linux 8 and 9 AppStream:

sudo dnf remove nodejs npm

NodeSource installs (all Rocky versions):

sudo dnf remove nodejs

Then clean up orphaned dependencies:

sudo dnf autoremove

If you used NodeSource, also remove the repository configuration:

sudo rm /etc/yum.repos.d/nodesource*.repo
sudo dnf clean all

Remove Node.js Installed via NVM

To remove a specific Node.js version installed through NVM, first switch away from it if it is currently active:

nvm deactivate

Then uninstall the version:

nvm uninstall 24.12.0

The next command deletes your entire ~/.nvm directory, including all Node.js versions installed with NVM. If you want a backup first, run cp -r ~/.nvm ~/.nvm-backup.

rm -rf ~/.nvm

Then edit ~/.bashrc (or your shell’s configuration file) and remove the lines that load NVM, which look like:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Conclusion

You now have Node.js installed on Rocky Linux with npm ready for package management. The DNF AppStream method provides the simplest path for production servers, while NodeSource offers access to the latest releases, and NVM gives developers flexibility to switch versions per project. With Node.js configured, you can begin building applications, installing frameworks like Express or Next.js, and managing dependencies through npm. For JavaScript development workflows, consider also setting up VS Code on Rocky Linux as your code editor.

Leave a Comment