How to Install and Use the Node Version Manager NVM
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
The Node Version Manager (NVM) is an open source version manager for Node.js (Node). NVM is easy to install and understand, and works on any POSIX-compliant shell (for example, sh or bash). NVM allows you to easily install different versions of Node and switch between them on a per-shell basis. This guide describes how to install NVM, and how to use it to install and run different versions of Node.
Advantages of NVM
Node changes quickly, and testing applications with different versions is often difficult. Since NVM enables quick and effortless switching between Node versions, it is much easier to test version compatibility and upgrades with multiple libraries. NVM stores the Node versions and associated modules inside your user directory, so
sudo does not have to be used. NVM also simplifies the installation and compilation process because Node versions no longer have to be obtained directly from the distribution channel.
A Summary of the NVM Installation and Configuration Process
A complete NVM installation consists of the following high-level steps. Each step is described below.
- Installing and Configuring NVM.
- Using NVM to Install Node.
- Using NVM to Run Node.
- Creating NVM Aliases.
Installing and Configuring NVM
These instructions are generally valid for most Linux distributions, although some of the
.bashrc directives might vary slightly on different shells. You can install and use NVM regardless of whether you have installed Node already. NVM alters
path variables to select different versions of Node, so it works with pre-existing installations.
We recommend you install Node using either
To install NVM using
curl, run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
To install NVM using
wget, run the following command:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
NoteYou can also install NVM using GIT or with a manual download and installation. Consult the GIT section of the NVM Documentation Guide for detailed instructions.
Source the new instructions NVM added to
.bashrcduring the installation process. You can either exit and re-enter the shell console, or manually source your
.bashrcfile. This file is almost always located at the root of your home directory.
As an alternate method, you can execute the new instructions in the same console to apply them immediately.
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
NVM uses the following environmental variables. We recommend leaving them at the default settings. Use caution if you decide to change them for any reason.
- NVM_DIR: NVM’s installation directory.
- NVM_BIN: The location where Node, the Node Package Manager (NPM), and global packages for the active version of Node are installed.
- NVM_INC: The directory for Node’s include files (for building C/C++ add-ons).
- NVM_CD_FLAGS: The flags used to maintain compatibility with
- NVM_RC_VERSION: The version from the
.nvmrcfile (if used).
Confirm you have successfully installed NVM.
command -v nvm
If the installation was successful, NVM returns
nvm. If you see the message
nvm: command not found, confirm the original installation completed successfully and repeat step #2 of this section to source the
You can confirm the version of NVM that is running with the following command:
Using NVM to Install Node
install command downloads, compiles, and installs the specified version of Node. You can install as many versions of Node as you want.
To install the current version of Node, run the following:
nvm install node
After a successful install, NVM displays information about the installation.
Now using node v15.5.1 (npm v7.3.0) Creating default alias: default -> node (-> v15.5.1)
NoteWhen used in a NVM command,
nodeis an alias for the latest version of Node. The first version of Node you installed automatically becomes the default version. A new shell instantiates with the current version of Node set to
default. The alias
systemrefers to the system-installed version of Node (if any).
To install a specific version of Node, specify the major or minor release number. You can preview a list of all available Node versions with the
NVM displays a long list of available versions in the following format:
Install any additional versions of Node you want to use. You can specify either a major or minor release of Node to install. When you install a new version of Node, NVM immediately begins using it and designates it as the current version.
nvm install 13.10.1 # Specific minor release nvm install 14 # Specify major release only
NoteIf you only specify the major release number for a Node version, NVM installs the latest version of that release. You can determine the latest version of each release from the output of
nvm ls-remote. Node also displays the exact version it selected after installation (for example,
Now using node v14.15.4). If you specify a version of Node that is not available, NVM responds with the error message
Version '15.0.2' not found - try 'nvm ls-remote' to browse available versions.
Using NVM to Run Node
Review all installed versions of Node with the
NVM returns a list of all Node versions and aliases, along with an arrow indicating the current version. Here is a sample output:
v13.10.1 v14.15.4 -> v15.5.1 default -> node (-> v15.5.1) iojs -> N/A (default) node -> stable (-> v15.5.1) (default) stable -> 15.5 (-> v15.5.1) (default)
To select a different version of Node, use the
nvm usecommand. Specify either the version number of Node (major or minor release) or an alias such as
nvm use node
nvm use 14
NVM confirms it is now using the new version.
You can also confirm the current version of Node with
Now using node v14.15.4
NVM again returns the current version number.
NoteYou can also confirm the version of Node currently in use with
node -v. To go back to using the system’s version of Node, run the command
nvm use system.
To switch to a new version of Node and immediately open a Node console, use
nvm run. The
runcommand is very similar to
nvm usein all other respects.
nvm run node
NVM confirms it is now running the selected version of Node and returns a Node prompt.
Running node v15.5.1 (npm v7.3.0) Welcome to Node.js v15.5.1. Type ".help" for more information. >
Creating NVM Aliases
You might find it convenient to refer to a Node version by a different or easier to remember name. NVM already provides some pre-made defaults such as
node, which refers to the latest version. But you can use the
alias command to change the value of an existing alias or create a brand-new alias.
nvm aliascommand to change the default Node version. Follow the
aliaskeyword with the
defaultalias and the new version of Node it should reference.
nvm alias default 14
NVM confirms the new value for the alias.
default -> 14 (-> v14.15.4)
nvm aliascommand to create a new alias. The following example defines a new
maintenancealias as Node version 13.10.1.
nvm alias maintenance 13.10.1
NVM confirms the new alias.
maintenance -> 13.10.1 (-> v13.10.1)
You can display all of the new and old aliases with the
Additional NVM Capabilities
Although NVM is very straightforward to use, it also provides some advanced capabilities. See the NVM GitLab page for a full list of all advanced topics.
NVM allows you to migrate packages from an earlier version of Node. The
nvm installcommand can be used with the optional
-reinstall-packages-from=flag to install a new version of Node with the packages from an earlier release. The following command installs the latest version of Node, but it also performs a reinstall of the packages from the
defaultversion of Node and links them.
nvm install node --reinstall-packages-from=default
NoteReinstalling packages does not update the NPM version.
NVM enables you to define custom colors to display the various Node versions and aliases. These colors are defined on the NVM GitLab page. Use the command
nvm set-colors <color-key>. If you add the
--no-colorsflag to a command, the information is displayed in black-and-white.
nvm set-colors rgBcm
You can also specify a default Node version number within the
.nvmrcfile. This file can be located in the root directory or in any parent directory. The version indicated in
.nvmrcis used if no version is specified on the command line.
Uninstalling Node Versions
NVM allows you to uninstall Node versions that are no longer required.
Run the command
nvm uninstallwith the version of Node you’d like to remove. You cannot remove a version you are currently using, so you must switch to a different version first.
nvm uninstall 13.10.1
NVM confirms the Node version has been removed.
Uninstalled node v13.10.1
If you no longer intend to use NVM, you can uninstall it with the
Deactivate NVM with the
nvm deactivatecommand. This clears any path variables.
Clean up your
.bashrcfile by removing the following lines:
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm
NoteIf you only want to go back to using the system’s version of Node, you do not have to uninstall NVM. In this case, run the command
nvm use system.
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
- [NVM GitHub Page(https://github.com/nvm-sh/nvm)
This page was originally published on