Linux Tutorials

Install NVM on CentOS Stream 9 & RHEL 9 — Step-by-Step Guide to Manage Node.js Versions

Installing NVM on CentOS Stream 9 or RHEL 9 is the most flexible way to manage multiple Node.js versions on development, CI, or production servers. In this comprehensive guide you'll learn how to prepare your system, install required build tools, install NVM (Node Version Manager) from the official repository, and then install, switch and pin Node.js versions. This article concentrates on CentOS Stream 9 and RHEL 9 specifics, including DNF usage and environment initialization. Follow the steps exactly to avoid common pitfalls, and use the sample command outputs to verify success. Main keyword: Install NVM on CentOS Stream 9.

Prepare the System and Install NVM

This section walks through the practical steps: update the OS packages, install development/build tools that Node versions may require (compilers, make, Python), download and run the official NVM install script, load NVM into your shell, and verify the installation. Each command below includes an example output and a brief explanation so you can confirm results on your own server. If you manage remote servers, run these commands over SSH as a regular user with sudo privileges; do not install NVM as root unless you intentionally want it tied to the root account.

sudo dnf update -y

Last metadata expiration check: 0:00:01 ago on Mon 07 Mar 2026 12:00:00 PM UTC.
Dependencies resolved.
================================================================================
 Package                     Architecture  Version                     Size
================================================================================
Upgrading:
 dnf                         noarch        4.9.0-2.el9                 1.0 M
 python3                     x86_64        3.9.11-1.el9                4.7 M

Transaction Summary
================================================================================
Upgrade  2 Packages

Total download size: 5.7 M
Downloading Packages:
(1/2): dnf-4.9.0-2.el9.noarch.rpm                    345 kB/s | 1.0 MB     00:02
(2/2): python3-3.9.11-1.el9.x86_64.rpm               1.2 MB/s | 4.7 MB     00:04
--------------------------------------------------------------------------------
Total                                                 4.7 MB/s | 5.7 MB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Upgrading        : python3-3.9.11-1.el9.x86_64                         1/2 
  Upgrading        : dnf-4.9.0-2.el9.noarch                               2/2 
  Running scriptlet: dnf-4.9.0-2.el9.noarch                               2/2 
  Cleanup          : python3-3.9.10-1.el9.x86_64                         1/2 
  Cleanup          : dnf-4.9.0-1.el9.noarch                               2/2 
  Verifying        : dnf-4.9.0-2.el9.noarch                               1/2 
  Verifying        : python3-3.9.11-1.el9.x86_64                         2/2 

Upgraded:
  dnf-4.9.0-2.el9.noarch python3-3.9.11-1.el9.x86_64

Complete!

The dnf update command refreshes package metadata and upgrades installed packages. The -y flag automatically answers yes to any prompts. The example output shows package downloads, transaction checks, and a successful upgrade; this ensures your system has the latest security fixes and dependencies before installing build tools or NVM.

sudo dnf groupinstall "Development Tools" -y

Last metadata expiration check: 0:00:02 ago on Mon 07 Mar 2026 12:01:00 PM UTC.
Dependencies resolved.
================================================================================
 Package                     Architecture  Version               Size
================================================================================
Installing group packages:
 autoconf                    noarch        2.71-2.el9            379 k
 automake                    noarch        1:1.16.4-7.el9        1.1 M
 binutils                    x86_64        2.35.1-47.el9         4.7 M
 bison                       x86_64        3.7.1-4.el9           1.3 M
 cpp                         x86_64        10.3.1-11.el9         6.8 M
 flex                        x86_64        2.6.4-9.el9           284 k
 make                        x86_64        4.3-4.el9             292 k
 gcc                         x86_64        10.3.1-11.el9         16 M

Transaction Summary
================================================================================
Install  9 Packages

Total download size: 31 M
Installed: autoconf automake binutils bison cpp flex make gcc ...
Complete!

The dnf groupinstall “Development Tools” command installs the common toolchain required to compile Node.js (compilers, make, autoconf, automake, etc.). The -y flag accepts the installation prompt. The output lists packages to be installed and confirms when the group is complete. Installing these tools prevents build failures when NVM compiles Node versions from source.

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

=> Downloading nvm from https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh
=> Installing nvm to /home/tecadmin/.nvm
=> Appending source lines to /home/tecadmin/.bashrc
=> Close and reopen your terminal or run 'source /home/tecadmin/.bashrc' to start using nvm

This command downloads and runs the official NVM install script. It writes necessary initialization lines to your shell profile (commonly ~/.bashrc), and places NVM files in ~/.nvm. The script URL includes a version tag — check the NVM GitHub repo for the latest version and replace v0.39.3 if necessary. Piping to bash runs the installer; review the script first if you require stricter security practices.

source ~/.bashrc

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

Running source ~/.bashrc reloads the shell profile so NVM functions are available in the current session. The example output shows the initialization lines that the installer added to your ~/.bashrc. Alternatively, you can close and reopen the terminal or SSH session to load NVM automatically.

nvm --version

0.39.3

Execute nvm –version to verify the installed NVM version. The output prints the NVM release number. If the command returns an error, confirm that your shell profile contains the NVM initialization lines and that you reloaded the shell.

nvm install --lts

Downloading and installing node v18.16.0 (npm v9.5.1)...
Downloading https://nodejs.org/dist/v18.16.0/node-v18.16.0-linux-x64.tar.xz...
Computing checksum with sha256sum
Checksums matched!
Now using node v18.16.0 (npm v9.5.1)
Creating default alias: lts -> 18.16.0

The nvm install –lts command installs the latest Long Term Support (LTS) version of Node.js. The –lts flag instructs NVM to select the current LTS release (recommended for most production and developer workloads). The output shows download progress, checksum verification, and the active Node version after installation.

nvm install 18.16.0

Downloading and installing node v18.16.0...
Now using node v18.16.0 (npm v9.5.1)

Use nvm install 18.16.0 to install a specific Node.js version. The output confirms the version download and that NVM set this version as active in the current shell. Replace 18.16.0 with any valid release number supported by NVM.

nvm use 18.16.0

Now using node v18.16.0 (npm v9.5.1)

The nvm use 18.16.0 command switches the active Node version for the current shell session. This does not change the system-wide Node installation; it only affects the current user session. The output confirms the Node and npm versions enabled.

nvm ls

         v16.20.0
->       v18.16.0
default -> 18.16.0 (-> v18.16.0)
node -> stable (-> v18.16.0) (default)
iojs -> N/A
unstable -> N/A
lts/* -> lts/hydrogen (-> v18.16.0)
lts/argon -> v4.9.1

The nvm ls command lists installed Node.js versions and shows which version is currently active (indicated by the arrow). The output helps you confirm installed versions and aliases. The default alias indicates the version NVM will use for new shells unless you override it.

nvm alias default 18.16.0

default -> 18.16.0 (-> v18.16.0)

Set a default Node.js version for all new shell sessions using nvm alias default 18.16.0. The output confirms the alias creation. When you open a new terminal, NVM will automatically activate the aliased version (unless overridden by a project .nvmrc file).

Conclusion

Installing NVM on CentOS Stream 9 and RHEL 9 is straightforward when you prepare the system and follow the recommended steps: update packages, install the Development Tools group, run the official NVM installer, and then install or switch Node versions. NVM simplifies managing multiple Node.js versions for different projects, CI pipelines, and testing scenarios. Keep your system updated, verify the installer source URL before piping to bash, and prefer LTS releases for production workloads. If you need to automate Node version setup for new user accounts or container images, add the NVM initialization lines to the appropriate shell profile templates (/etc/skel, or a custom entrypoint) so new shells load NVM automatically.

One Comment

  1. Really helpful — installing NVM on CentOS Stream 9 simplified managing multiple Node.js versions for me; one suggestion: add a short note about making nvm available in non-login shells (sourcing the right profile) or using a system-wide wrapper if you need it across users.

Komentariši

Vaša email adresa neće biti objavljivana. Neophodna polja su označena sa *