NVM
Ce contenu n’est pas encore disponible dans votre langue.
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.
Installing and Configuring NVM
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.
Installing NVM on macOS
To install NVM on macOS, follow these steps:
- Open your terminal.
- Install NVM by running the following command:
- After the installation is complete, close and reopen your terminal.
- Verify the installation by running the following command:
If everything is set up correctly, you should see the NVM version number.
Installing NVM on Linux
To install NVM on Linux, follow these steps:
- Open your terminal.
- Install NVM by running the following command:
- After the installation is complete, close and reopen your terminal.
- Verify the installation by running the following command:
If everything is set up correctly, you should see the NVM version number.
Installing NVM on Windows
To install NVM on Windows, follow these steps:
- Download the NVM Windows installer from the NVM for Windows GitHub repository .
- Run the installer and follow the on-screen instructions.
- Once the installation is complete, open a new command prompt or PowerShell window.
- Verify the installation by running the following command:
If everything is set up correctly, you should see the NVM version number.
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.
Install the Latest Version
To install the latest version of Node, run the following:
After a successful install, NVM displays information about the installation:
Install A Specific Version of Node
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 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:
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:
- You should see the following output:
- 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: - 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:
- 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:
List Node Versions with NVM
Review all installed versions of Node with the ls
command:
NVM returns a list of all Node versions and aliases, along with an arrow indicating the current version:
Using NVM to Run Node
To select a different version of Node, use the nvm use
command.
- Specify the version number of Node (major or minor release):
- Alternatively, use an alias such as node:
- You can confirm the current version of Node with
nvm current
:
- You can also confirm the version of Node currently in use with the
-v
flag:
Run Node
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 confirms it is now running the selected version of Node and returns a Node prompt:
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 confirms the Node version has been removed.
Useful Resources
- NVM GitHub https://github.com/nvm-sh/nvm