Пропустить до содержимого

NVM

Это содержимое пока не доступно на вашем языке.

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:
Terminal window
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  • After the installation is complete, close and reopen your terminal.
  • Verify the installation by running the following command:
Terminal window
nvm --version

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:
Terminal window
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  • After the installation is complete, close and reopen your terminal.
  • Verify the installation by running the following command:
Terminal window
nvm --version

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:
Terminal window
nvm --version

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:

Terminal window
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)

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:

Terminal window
nvm ls-remote

NVM displays a long list of available versions in the following format:

v20.7.0
v20.8.0
v20.8.1
v20.9.0(LTS: Iron)
v20.10.0(LTS: Iron)
v20.11.0(LTS: Iron)
v20.11.1(Latest LTS: Iron)
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.

Terminal window
nvm install 20.8.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 v20.8.1...
Downloading https://nodejs.org/dist/v20.8.1/node-v20.8.1-linux-x64.tar.xz...
######################################################################### 100.0 %
Computing checksum with sha256sum
Checksums matched!
Now using node v20.8.1(npm v10.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)

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:
Terminal window
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:
  • 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:
Terminal window
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:
Terminal window
nvm use lts/gallium
Now using node v16.20.2 (npm v8.19.4)

List Node Versions with NVM

Review all installed versions of Node with the ls command:

Terminal window
nvm ls

NVM returns a list of all Node versions and aliases, along with an arrow indicating the current version:

v12.7.0
-> v12.22.1
v14.21.2
v18.14.0
v18.19.0
system
default -> v12.22.1
node -> stable(-> v18.19.0) (default)
stable -> 18.19(-> v18.19.0) (default)
iojs -> N/A (default)
lts/* -> lts/iron (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.19.1 (-> N/A)
lts/iron -> v20.11.1 (-> N/A)

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):
Terminal window
nvm use 14
Now using node v14.21.2 (npm v6.14.17)
  • Alternatively, use an alias such as node:
Terminal window
nvm use node
Now using node v18.19.0 (npm v10.2.3)
  • You can confirm the current version of Node with nvm current :
Terminal window
nvm current
v18.19.0
  • You can also confirm the version of Node currently in use with the -v flag:
Terminal window
node -v
v18.19.0

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.

Terminal window
nvm run node

NVM confirms it is now running the selected version of Node and returns a Node prompt:

Running node v18.19.0(npm v10.2.3)
Welcome to Node.js v18.19.0.
Type ".help" for more information.
>
(To exit, press Ctrl+C again or Ctrl+D or type .exit)

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.

Terminal window
nvm uninstall 17.0.1

NVM confirms the Node version has been removed.

Uninstalled node v17.0.1

Useful Resources