Product docs and API reference are now on Akamai TechDocs.
Search product docs.
Search for “” in product docs.
Search API reference.
Search for “” in API reference.
Search Results
 results matching 
 results
No Results
Filters
Installing and Using NVM (Node Version Manager)
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 understand and works on any POSIX-compliant shell (e.g. sh or bash). NVM allows you to easily install and manage 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
Because Node changes quickly, 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
is not necessary. 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, and each is detailed in the sections below:
Install NVM
These instructions cover how to install NVM. While these are generally valid for most Linux distributions, some of the .bashrc
directives might vary slightly on different shells. You can install and use NVM regardless of whether you have already installed Node. NVM alters path
variables to select different versions of Node, so it works with pre-existing installations.
Install NVM using either
curl
orwget
: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
Note 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
.bashrc
during the installation process. You can either exit and re-enter the shell console, or manually source your.bashrc
file. This file is almost always located at the root of your home directory:source ~/.bashrc
Note Alternatively, 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:
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 withzsh
.NVM_RC_VERSION
: The version from the.nvmrc
file (if used).
We recommend leaving the default settings. Use caution if changing them for any reason.
Confirm that NVM is successfully installed:
command -v nvm
If the installation was successful, NVM returns
nvm
:nvm
If you see the message
nvm: command not found
, confirm the original installation completed successfully and repeat step two of this section to source the.bashrc
file.Confirm the version of NVM that is running with the following command:
nvm --version
0.37.2
Use NVM to Install Node
NVM’s 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 latest version of Node, run the following:
nvm install node
After a successful install, NVM displays information about the installation:
Now using node v21.0.0 (npm v10.2.0) Creating default alias: default -> node (-> v21.0.0)
Note When used in an NVM command,node
is 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 aliassystem
refers 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-remote
command:nvm ls-remote
NVM displays a long list of available versions in the following format:
v0.1.14 v0.1.15 v0.1.16 ... v20.8.0 v20.8.1 -> v21.0.0
Install any additional versions of Node you want to use. You can specify either a major or minor release of Node to install.
nvm install 17.0.1 # Specific minor release nvm install 19 # Specify major release only
When you install a new version of Node, NVM immediately begins using it and designates it as the current version:
Downloading and installing node v17.0.1... Downloading https://nodejs.org/dist/v17.0.1/node-v17.0.1-linux-x64.tar.xz... ######################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v17.0.1 (npm v8.1.0) Downloading and installing node v19.9.0... Downloading https://nodejs.org/dist/v19.9.0/node-v19.9.0-linux-x64.tar.xz... ######################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v19.9.0 (npm v9.6.3)
Note 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 (e.g.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.
List Node Versions with NVM
Review all installed versions of Node with the ls
command:
nvm ls
NVM returns a list of all Node versions and aliases, along with an arrow indicating the current version:
v17.0.1
-> v19.9.0
v21.0.0
default -> node (-> v21.0.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v21.0.0) (default)
stable -> 21.0 (-> v21.0.0) (default)
The NVM Use Command
To select a different version of Node, use the nvm use
command.
Specify the version number of Node (major or minor release):
nvm use 17
Now using node v17.0.1 (npm v8.1.0)
Alternatively, use an alias such as
node
:nvm use node
Now using node v21.0.0 (npm v10.2.0)
You can confirm the current version of Node with
nvm current
:nvm current
v21.0.0
You can also confirm the version of Node currently in use with the
-v
flag:node -v
v21.0.0
To use the system’s version of Node, run the command:
nvm use system
NVM: Switch Node Version
To switch to a different version of Node and immediately open a Node console, use nvm run
. The run
command is very similar to nvm use
in all other respects.
nvm run node
NVM confirms it is now running the selected version of Node and returns a Node prompt:
Running node v21.0.0 (npm v10.2.0)
Welcome to Node.js v21.0.0.
Type ".help" for more information.
>
To exit the Node prompt and return to the Linux terminal, press Control+C twice or issue the following command:
.exit
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. However, you can use the alias
command to change the value of an existing alias or create a brand-new alias.
Use the
nvm alias
command to change the default Node version. Follow thealias
keyword with thedefault
alias and the new version of Node it should reference:nvm alias default 19
NVM confirms the new value for the alias:
default -> 19 (-> v19.9.0)
Also use the
nvm alias
command to create a new alias. The following example defines a newmaintenance
alias as Node version 17.0.1:nvm alias maintenance 17.0.1
NVM confirms the new alias:
maintenance -> 17.0.1 (-> v17.0.1)
Display all of the new and old aliases with the
nvm ls
command:nvm ls
v17.0.1 v19.9.0 -> v21.0.0 default -> 19 (-> v19.9.0) maintenance -> 17.0.1 (-> v17.0.1) iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v21.0.0) (default) stable -> 21.0 (-> v21.0.0) (default)
Use NVM to Install Latest LTS Node.js Release
Any Node.js version can be in one of the following three release phases: Current, Long Term Support (LTS), and Maintenance. The LTS release includes new features, bug fixes, and updates that have been approved. This section shows how to install the latest LTS version of Node.js using NVM.
Use the following command to install the latest LTS version of Node.js on your system:
nvm install --lts
You should see the following output:
Installing latest LTS version. Downloading and installing node v18.18.2... Downloading https://nodejs.org/dist/v18.18.2/node-v18.18.2-linux-x64.tar.xz... ######################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v18.18.2 (npm v9.8.1)
After the installation is complete NVM automatically switches to the latest LTS version of Node.js that you just installed.
To install a specific LTS release other than the latest, use the
--lts
argument along with the release name that you want to install. The example command installs the “gallium” LTS (v16) release of Node.js:nvm install --lts=gallium
Installing with latest version of LTS line: gallium Downloading and installing node v16.20.2... Downloading https://nodejs.org/dist/v16.20.2/node-v16.20.2-linux-x64.tar.xz... ######################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v16.20.2 (npm v8.19.4)
Refer to the Node.js Releases page for LTS release names.
To switch to the latest LTS version of Node.js that is already installed on your system, use the following command:
nvm use --lts
Now using node v18.18.2 (npm v9.8.1)
To switch to a specific LTS version of Node.js, append
/RELEASE_NAME
to the command. This example switches to the “gallium” LTS line of Node.js:nvm use lts/gallium
Now using node v16.20.2 (npm v8.19.4)
Additional NVM Capabilities
Although NVM is very straightforward to use, it also provides some advanced capabilities. See the NVM GitHub page for a full list of all advanced topics.
NVM allows you to migrate packages from an earlier version of Node. The
nvm install
command 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 thedefault
version of Node and links them.nvm install node --reinstall-packages-from=default
v21.0.0 is already installed. Now using node v21.0.0 (npm v10.2.0) Reinstalling global packages from v19.9.0... changed 1 package in 1s Linking global packages from v19.9.0... No linked global packages found...
Note Reinstalling packages does not update the NPM version.NVM enables you to define custom colors to display the various Node versions and aliases using the
nvm set-colors COLOR_KEY
command. These colors are defined on the NVM GitHub page . If you add the--no-colors
flag 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 an
.nvmrc
file. This file can be located in the root directory or in any parent directory. The version indicated in.nvmrc
is used if no version is specified on the command line.
Use NVM to Uninstall Node
NVM allows you to uninstall Node versions that are no longer required.
Run the command nvm uninstall
with the version of Node you’d like to remove.
nvm uninstall 17.0.1
NVM confirms the Node version has been removed.
Uninstalled node v17.0.1
NVM Uninstall Steps
If you no longer intend to use NVM, you can uninstall it with the unload
command.
First, deactivate NVM with the
nvm deactivate
command to clear any path variables:nvm deactivate
Next, use the
unload
command to uninstall NVM:nvm unload
Clean up your
.bashrc
file 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
nvm use system
instead.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.
This page was originally published on