How to Install and Manage Node.js Versions with NVM on Windows, macOS, and Linux
Managing multiple versions of Node.js can be tricky, especially if you’re juggling projects requiring different Node.js versions. Thankfully, Node Version Manager (NVM) simplifies the process, allowing you to install, switch, and manage multiple Node.js versions effortlessly.
In this beginner-friendly guide, we’ll cover how to install and use NVM on Windows, macOS, and Linux. Whether you’re new to Node.js or an experienced developer, this guide will help you get started with ease!
Installing and Managing Node.js with NVM on Windows
Step 1: Install NVM for Windows
- Visit the official NVM for Windows repository: NVM for Windows GitHub.
- Download the latest
nvm-setup.zip
from the releases section. - Extract the zip file and run the
nvm-setup.exe
installer. - Follow the installation wizard and ensure to check the option to add NVM to the system PATH.
Step 2: Install Node.js Using NVM
- Open a Command Prompt or PowerShell window.
- To install the latest version of Node.js, run:
nvm install latest
- To install a specific version, run:
nvm install [version]
Example:nvm install 14.17.0
Step 3: Use a Specific Node.js Version
Switch between installed versions by running:
nvm use [version]
Step 4: Verify the Installed Version
To check the current version of Node.js in use, type:
node --version
Installing and Managing Node.js with NVM on macOS
Step 1: Install NVM
- Open the Terminal (
Cmd + Space
, typeTerminal
). - Install NVM by running:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- Restart the terminal or run the following command to load NVM:
source ~/.nvm/nvm.sh
Step 2: Verify NVM Installation
Ensure NVM is installed by typing:
nvm --version
Step 3: Install Node.js Using NVM
- Install the latest version of Node.js:
nvm install node
- Install a specific version:
nvm install [version]
Step 4: Switch Node.js Versions
To switch between versions, use:
nvm use [version]
Step 5: Set Default Node.js Version
To make a version the default, run:
nvm alias default [version]
Installing and Managing Node.js with NVM on Linux
Step 1: Install NVM
- Open the Terminal (
Ctrl + Alt + T
). - Run the following command to install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- Reload your shell configuration:
source ~/.bashrc
Step 2: Verify NVM Installation
Check the installation by running:
nvm --version
Step 3: Install Node.js Using NVM
- Install the latest Node.js version:
nvm install node
- Install a specific version:
nvm install [version]
Step 4: Manage Node.js Versions
- Switch versions:
nvm use [version]
- Set a default version:
nvm alias default [version]
Why Use NVM?
- Flexibility: Easily switch between Node.js versions for different projects.
- Version Isolation: Prevent compatibility issues by using project-specific versions.
- Ease of Use: Simple commands make managing Node.js versions a breeze.
Conclusion
Congratulations! You’ve successfully installed and learned how to manage Node.js versions with NVM on Windows, macOS, and Linux. NVM simplifies your workflow, especially when handling multiple projects with varying Node.js requirements.
If you found this guide helpful or have questions, let us know in the comments below! We’d love to hear your feedback and help you further. 😊