Introduction to NVM
What is NVM?
NVM (Node Version Manager) is a tool that allows you to easily install, manage, and work with multiple Node.js versions on your system. It provides a command-line interface to switch between different versions of Node.js, ensuring that you can use the specific version required for each of your projects.
There are two main implementations of NVM:
- nvm-windows: A Windows-specific implementation
- nvm-sh: The original implementation for Unix-like systems (Linux, macOS, WSL)
This documentation covers both implementations, with specific sections for each when their usage differs.
Why Use NVM?
Multiple Node.js Versions
Different projects may require different Node.js versions. With NVM, you can:
- Install multiple Node.js versions on a single machine
- Switch between versions with a simple command
- Set a default version for new terminal sessions
- Use project-specific Node.js versions via
.nvmrc
files
Testing Across Versions
NVM makes it easy to test your code against different Node.js versions to ensure compatibility.
Staying Up-to-Date
NVM allows you to easily upgrade to the latest Node.js versions while keeping older versions available for legacy projects.
Avoiding Permission Issues
Installing Node.js globally often leads to permission issues when installing global packages. NVM installs Node.js in your user directory, avoiding these common permission problems.
Key Features
For nvm-windows
- Install and manage multiple Node.js versions on Windows
- Switch between Node.js versions with a simple command
- Set a default Node.js version
- Use
.nvmrc
files for project-specific versions - Configure mirrors for faster downloads in certain regions
- Support for both 32-bit and 64-bit architectures
For nvm-sh (Linux/macOS/WSL)
- Install and manage multiple Node.js versions
- Automatic version switching based on
.nvmrc
files - Support for bash, zsh, and other shells
- Extensive scripting capabilities
- Support for custom installation directories
Getting Started
To get started with NVM, you'll need to:
- Download the appropriate version for your operating system
- Install NVM on your system
- Learn the basic usage of NVM commands
Comparison with Other Tools
NVM vs. Direct Node.js Installation
Feature | NVM | Direct Node.js Installation |
---|---|---|
Multiple versions | ✅ Yes | ❌ No |
Easy version switching | ✅ Yes | ❌ No |
Project-specific versions | ✅ Yes | ❌ No |
Permission issues | ✅ Avoided | ❌ Common |
Initial setup | More steps | Simpler |
NVM vs. Other Version Managers
There are several other Node.js version managers available:
- n: A simpler Node.js version manager for Unix-like systems
- nodenv: Inspired by rbenv, for Unix-like systems
- nodist: An alternative for Windows
- volta: A newer tool that manages JavaScript tools beyond just Node.js
NVM remains one of the most popular and well-maintained options with strong community support.
Next Steps
Now that you understand what NVM is and its benefits, you can:
- Download NVM for your operating system
- Follow the installation guide to set up NVM
- Learn the basic commands to manage your Node.js versions
- Configure mirrors for faster downloads (if needed)
- Check the FAQ for common questions and troubleshooting