Installing Node Version Manager (NVM) in CentOS involves a few simple steps. Here's how to do it:
1. Install Dependencies
Before installing NVM, ensure you have the necessary dependencies:
- Curl: This tool is used to download the NVM installation script. You can install curl using
sudo yum install curl
. - Bash: NVM requires a Bash shell environment. CentOS comes with Bash pre-installed.
2. Download NVM Installation Script
Use curl to download the NVM installation script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
This command fetches the script from the NVM GitHub repository and executes it.
3. Verify NVM Installation
After the installation completes, you can verify it by running:
nvm --version
This should display the installed NVM version.
4. Source NVM Script
To use NVM, you need to source the NVM script in your shell environment. You can do this by adding the following line to your .bashrc
file:
source ~/.nvm/nvm.sh
After adding this line, you can either close and reopen your terminal or run source ~/.bashrc
to load the changes.
5. Install Node.js
Now that NVM is installed, you can use it to install different Node.js versions. For example, to install Node.js version 16.x, use:
nvm install 16
You can then use nvm use 16
to switch to this version.
Conclusion
Following these steps will successfully install NVM on your CentOS system. You can now easily manage and switch between different Node.js versions using NVM.