
Node.js is a JavaScript runtime environment with multiple versions. When working on different projects, you may need specific versions of Node.js. NVM (Node Version Manager) makes it easy to install and switch between different versions of Node.js. In this guide, we will go over how to install NVM on different operating systems and how to use it effectively.
1. What is NVM?
NVM (Node Version Manager) is a tool that allows you to install and manage multiple versions of Node.js effortlessly. With NVM, you can ensure that each project uses the appropriate Node.js version.
Key Features of NVM:
- Install and remove multiple versions of Node.js
- Easily switch between versions
- Use different versions for different projects
- Manage Node.js with simple commands
2. Installing NVM on Different Operating Systems
1) Installing NVM on macOS and Linux
1. Install NVM
Open a terminal and run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
Alternatively, if you prefer wget
:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
2. Apply Environment Variables
After installation, run the following command to apply the changes:
source ~/.bashrc # For Bash users
source ~/.zshrc # For Zsh users
3. Verify Installation
To check if NVM is installed correctly, run:
nvm --version
If the version number appears, the installation was successful.
2) Installing NVM on Windows
On Windows, you need to use nvm-windows
instead of the official NVM.
1. Install NVM for Windows
- Visit the nvm-windows latest release page.
- Download and run the
nvm-setup.exe
file. - Follow the installation steps, keeping the default settings.
- Once installed, open Command Prompt (CMD) or PowerShell and run the following command to verify the installation:
nvm version
If a version number appears, NVM has been successfully installed.
3. Basic NVM Commands
1) Install the Latest Node.js Version
nvm install node
Or, to install a specific version:
nvm install 18.17.1 # Example: Install Node.js 18.17.1
2) Use a Specific Version
nvm use 18.17.1
3) List Installed Node.js Versions
nvm list
4) Remove a Specific Version
nvm uninstall 18.17.1
4. Managing Node.js Versions Per Project
With NVM, you can set different Node.js versions for different projects. To do this, create a .nvmrc
file in the project folder and specify the required version.
For example, run the following command inside a project folder to create a .nvmrc
file:
echo "18.17.1" > .nvmrc
Then, whenever you enter the project directory, run the following command to automatically switch to the specified version:
nvm use
5. Conclusion
Now you can easily manage Node.js versions using NVM. Set the required version for each project and quickly switch between them as needed. You can choose between the latest versions or stable LTS versions depending on your requirements.