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
curlorwget.To install NVM using
curl, run the following command:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashTo install NVM using
wget, run the following command:wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashNote
You 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.source ~/.bashrcAs 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_completionNote
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
zsh. - NVM_RC_VERSION: The version from the
.nvmrcfile (if used).
Confirm you have successfully installed NVM.
command -v nvmIf the installation was successful, NVM returns
nvm. If you see the messagenvm: command not found, confirm the original installation completed successfully and repeat step #2 of this section to source the.bashrcfile.nvmYou can confirm the version of NVM that is running with the following command:
nvm --version
Using NVM to Install Node
The 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 nodeAfter 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)Note
When 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 todefault. The aliassystemrefers 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
ls-remotecommand.nvm ls-remoteNVM displays a long list of available versions in the following format:
v5.12.0 v6.0.0Install 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 onlyNote
If 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 ofnvm 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 messageVersion '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
lscommand.nvm lsNVM 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 asnode.nvm use nodeor
nvm use 14NVM confirms it is now using the new version.
You can also confirm the current version of Node withNow using node v14.15.4nvm current.nvm currentNVM again returns the current version number.
v14.15.4Note
You can also confirm the version of Node currently in use withnode -v. To go back to using the system’s version of Node, run the commandnvm use system.To switch to a new version of Node and immediately open a Node console, use
nvm run. Theruncommand is very similar tonvm usein all other respects.nvm run nodeNVM 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 default and 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.
Use the
nvm aliascommand to change the default Node version. Follow thealiaskeyword with thedefaultalias and the new version of Node it should reference.nvm alias default 14NVM confirms the new value for the alias.
default -> 14 (-> v14.15.4)Use the
nvm aliascommand to create a new alias. The following example defines a newmaintenancealias as Node version 13.10.1.nvm alias maintenance 13.10.1NVM confirms the new alias.
maintenance -> 13.10.1 (-> v13.10.1)You can display all of the new and old aliases with the
nvm lscommand.nvm ls
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 thedefaultversion of Node and links them.nvm install node --reinstall-packages-from=defaultNote
Reinstalling 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 rgBcmYou 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.1NVM confirms the Node version has been removed.
Uninstalled node v13.10.1
Uninstalling NVM
If you no longer intend to use NVM, you can uninstall it with the unload command.
Deactivate NVM with the
nvm deactivatecommand. This clears any path variables.nvm deactivateUninstall NVM.
nvm unloadClean 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 commandnvm use system.
More Information
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



