# Installing Node Version Manager (nvm)
# Why use a Node Version Manager?
A Node version manager allows you to easily install and switch between numerous versions of Node.js (opens new window). This is useful when a project youβre working on requires a different version of Node.js (opens new window) than what you currently have installed.
# Installation
We'll be going over how to install nvm (opens new window) on Linux and macOS.
Windows
Windows is not supported, but you can get it to work by setting up Windows Subsystem for Linux (WSL) (opens new window), GitBash (opens new window), or Cygwin (opens new window). Other alternatives exist that are not supported or developed by nvm (opens new window) like nvm-windows (opens new window). Check out the nvm Important Notes (opens new window) for more alternatives and details.
Before installing make sure your using a POSIX-compliant shell like sh
, dash
, ksh
, zsh
, or bash
.
Fish Shell
If you want to use fish (opens new window), then check out the nvm Important Notes (opens new window) repository for alternatives.
If you run into any issues with installation, then be sure to check out the nvm (opens new window) repository for any updates and troubleshooting tips.
# Linux Dependencies
You can install nvm (opens new window) using either curl
or wget
.
Here's how to install curl
for Linux:
Here's how to install wget
for Linux:
# macOS Dependencies
macOS should already have curl
installed, but you can use Homebrew (opens new window) to upgrade to the latest version:
If you want to use wget
on macOS, then you can use Homebrew (opens new window) to install it:
If you're using OS X 10.9 or newer, you'll need to install Xcode (opens new window) or just the Command Line Tools
.
Here's a good post explaining how to install Xcode (opens new window):
If you don't want to install Xcode (opens new window), then you can install only the Command Line Tools
by following along with this post:
# System Version
If you have a system version of Node.js (opens new window), i.e., you downloaded and installed Node.js (opens new window) without using nvm (opens new window), then version mismatches may occur.
This can occur since versions installed by nvm (opens new window) will only be available to the user account it was installed on, and any other user accounts will use the system version.
If version mismatches are occurring or any other issues, then you can uninstall node
and npm
associated with the system version and just use versions installed by nvm (opens new window).
Be sure to uninstall any globally installed npm
packages associated with the system version as well.
Also, if you're using a ~/.npmrc
file it may not be compatible see nvm Compatibility Issues (opens new window) in which case you should remove it.
When using nvm (opens new window), you don't need to use sudo npm install -g <package>
instead use npm install -g <package>
when installing global packages.
Finally, if you're using a different node version manager like fnm (opens new window), then you may run into issues with your installed versions from nvm (opens new window). If this is the case, then uninstall the node version manager you will not be using to resolve the issues.
Preferred Node Manager
My preferred way to manage my node versions is with fnm (opens new window). Check out Installing Fast Node Manager (fnm) to learn more about it.
# Install and Update Script
After installing the necessary dependencies, you can install or update nvm (opens new window) by using curl
or wget
on Linux or macOS:
The above commands will download and run a script to install or update nvm (opens new window).
The script clones the nvm (opens new window) repository to ~/.nvm
.
Additional Notes
If you're interested, check out the nvm Additional Notes (opens new window) for information on more parameters and how to customize the install source, directory, profile, and version for the install script.
After running the command above, you'll be prompted to close and reopen your terminal to start using nvm (opens new window), or you can run the following commands to start using it in the current shell session:
The third line provides autocompletion for nvm (opens new window). Here's some examples of the autocompletion usage (opens new window).
# Verify Installation
To verify the installation you can run the following command:
If the installation was successful, then the command should output nvm
.
If you get no output after running the above command, then see the troubleshooting sections below.
# Troubleshooting
Try closing the current terminal and opening a new terminal. Then try verifying the installation again.
Here are some examples of commands you can run depending on your shell:
After running the command for your shell, try verifying the installation again.
If you're still experiencing issues verifying your installtion for Linux, then check out Troubleshooting on Linux (opens new window).
For macOS check out Troubleshooting on macOS (opens new window) and macOS Troubleshooting (opens new window) which contain more specific information related to shell issues and to issues with Macs using the M1 chip.
For more general issues check out the Problems (opens new window) section.
Other Installation Methods
Instead of using the script above, you can also perform a git install (opens new window) or a manual install (opens new window) as well as a manaul upgrade (opens new window). The minimum required git (opens new window) version for the installation methods is v1.7.10.
# Usage
Here are some useful commands to get started with nvm (opens new window). You can run nvm --help
to see a list of commands, their flags, and descriptions.
# Check nvm Version
The following command will display the version of nvm (opens new window):
# List Remote Versions
The following commands will list the remote versions of Node.js (opens new window).
List the all remote versions by using ls-remote
:
Node.js (opens new window) has a release schedule (opens new window) for long-term support (LTS).
List the LTS remote versions by using --lts
:
List all of the LTS remote versions for a specific line by using, e.g., --lts=boron
:
List all of the LTS remote versions for a given version number by providing, e.g., 16 to ls-remote
:
# Install Versions
The following commands are examples of how to install different versions of Node.js (opens new window).
If you try to install a version and the installation fails, then run nvm cache clear
to delete the cached versions.
Install the latest version by using the special default alias node
:
Install the latest LTS version by using --lts
:
Install the latest LTS version for a specific line by using, e.g., --lts=boron
:
Install a specific version by providing a version number:
# List Installed Versions
The following command will list all of the installed versions of Node.js (opens new window):
# Use a Version
The following commands will set which version of Node.js (opens new window) to use.
Use the latest version by using the special default alias node
:
Use the latest LTS version by using --lts
:
Use the latest LTS version for a specific line by using, e.g., --lts=boron
:
Use a specific version by providing a version number:
If you have a system version installed, then you can use the special default alias system
to use it:
# Check Active Version
Check the currently active Node.js (opens new window) version by using current
:
# Set Aliases
Set an alias for a specific Node.js (opens new window) version by provding a name and a version.
Here, version 16.11.1 will get an alias of nickname:
The default version is the active version when opening new shells. The first installed version will get set as the default version. To change the default version run the command below.
Here, we're setting the default version to be 17.1.0:
# Get Path to Version
The following commands will get the path of where a Node.js (opens new window) version was installed.
Get the path of where a version was installed by specifying a version number:
Get the path to where a version is installed by specifying an alias:
# Uninstall Versions
The following commands are examples of how to uninstall different versions of Node.js (opens new window).
Uninstall the latest version by using the special default alias node
:
Uninstall the latest LTS version by using --lts
:
Uninstall the latest LTS version for a specific line by using, e.g., --lts=boron
:
Uninstall a specific version by providing a version number:
# Uninstall nvm
To uninstall nvm (opens new window) run the following:
Then remove these lines from your ~/.bashrc
, ~/.zshrc
, ~/.profile
, etc.