Node Version Manager (NVM) is a popular utility that enables you to manage multiple versions of Node.js on your system. It allows you to switch between different Node.js versions easily, making it a valuable tool for developers working on different projects with varying requirements. In this article, we will guide you through the process of installing NVM on CentOS Stream 9 and RHEL 9.
Prerequisites
Before we begin, ensure that you have the following:
- A system running CentOS Stream 9 or RHEL 9
- A user account with shell access
Step 1: Update Your System
First, it’s a good idea to update your system to ensure you have the latest packages and security updates. Run the following command:
sudo dnf update -y
Step 2: Install Build Tools
To compile and install Node.js versions, you will need some build tools. Run the following command to install them:
sudo dnf groupinstall "Development Tools" -y
Step 3: Install NVM
Now, we will install NVM by using the official install script from the NVM GitHub repository. Run the following command to download and execute the script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Note: The version number (v0.39.3) may change, so be sure to check the NVM repository (https://github.com/nvm-sh/nvm) for the latest release.
Once the script finishes execution, it will install NVM and add the necessary lines to your shell’s configuration file (such as .bashrc, .zshrc, or .bash_profile).
To apply the changes, you need to restart your shell or run the following command:
source ~/.bashrc
To verify that NVM is installed correctly, run:
nvm --version
If you see the version number displayed, NVM is successfully installed.
Step 4: Install Node.js
With NVM installed, you can now install different versions of Node.js. To install the latest LTS (Long Term Support) version, run:
nvm install --lts
To install a specific version, use the following command:
nvm install 18.16.0
Replace “18.16.0” with the desired version number.
Step 5: Switch Between Node.js Versions
NVM allows you to switch between installed Node.js versions easily. To switch to a specific version, use the following command:
nvm use 18.16.0
Replace “18.16.0” with the version number you want to switch to.
To view a list of all installed Node.js versions, run:
nvm ls
To set the default Node.js version that will be used every time you open a new terminal, run:
nvm alias default 18.16.0
Replace “18.16.0” with the desired version number.
Conclusion
You have now successfully installed NVM on your CentOS Stream 9 or RHEL 9 system and learned how to manage multiple Node.js versions. With NVM, you can easily switch between different Node.js versions to work on projects with varying requirements.