Windows利用nvm进行node版本控制(node 版本管理工具nvm的安装与使用)

为什么需要对node进行版本管理?

  • 不同项目的node的版本并不相同,不同版本之间的兼容性并不好,所以需要工具(node 版本管理工具)进行快速切换node版本。

下载与安装nvm(Windows)

1.卸载电脑原有node

直接去 控制面板/win11设置 卸载就行

2.安装nvm

Github下载地址

下载地址里面有两类

  • nvm-noinstall:绿色免安装版(使用时需进行配置)
  • nvm-setup:安装版(本次选择

Github下载地址中选择nvm-setup.exe文件下载,双击安装即可。
注意:安装目录不要出现空格/中文,避免奇奇怪怪的bug

安装完成后在控制台输入 nvm, 出现类似下面图片的内容就代表安装成功。
image

使用nvm(安装/管理nodejs)

  1. 查看本地安装的所有版本:nvm list
C:\Users\kingwzun>nvm list

No installations recognized.

  1. 查看所有可下载的版本:nvm list available
C:\Users\kingwzun>nvm list available

|   CURRENT    |     LTS      |  OLD STABLE  | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
|    21.4.0    |   20.10.0    |   0.12.18    |   0.11.16    |
|    21.3.0    |    20.9.0    |   0.12.17    |   0.11.15    |
|    21.2.0    |   18.19.0    |   0.12.16    |   0.11.14    |
|    21.1.0    |   18.18.2    |   0.12.15    |   0.11.13    |
|    21.0.0    |   18.18.1    |   0.12.14    |   0.11.12    |
|    20.8.1    |   18.18.0    |   0.12.13    |   0.11.11    |
|    20.8.0    |   18.17.1    |   0.12.12    |   0.11.10    |
|    20.7.0    |   18.17.0    |   0.12.11    |    0.11.9    |
|    20.6.1    |   18.16.1    |   0.12.10    |    0.11.8    |
|    20.6.0    |   18.16.0    |    0.12.9    |    0.11.7    |
|    20.5.1    |   18.15.0    |    0.12.8    |    0.11.6    |
|    20.5.0    |   18.14.2    |    0.12.7    |    0.11.5    |
|    20.4.0    |   18.14.1    |    0.12.6    |    0.11.4    |
|    20.3.1    |   18.14.0    |    0.12.5    |    0.11.3    |
|    20.3.0    |   18.13.0    |    0.12.4    |    0.11.2    |
|    20.2.0    |   18.12.1    |    0.12.3    |    0.11.1    |
|    20.1.0    |   18.12.0    |    0.12.2    |    0.11.0    |
|    20.0.0    |   16.20.2    |    0.12.1    |    0.9.12    |
|    19.9.0    |   16.20.1    |    0.12.0    |    0.9.11    |
|    19.8.1    |   16.20.0    |   0.10.48    |    0.9.10    |

This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases
  1. 安装特定版本node:nvm install 18.19.0
    (命令中的版本号18.19.0可自定义,具体参考nvm list available查询出来的列表)

如果安装成功命令行输出如下:

C:\Users\kingwzun>nvm install 18.19.0
Downloading node.js version 18.19.0 (64-bit)...
Extracting node and npm...
Complete
npm v10.2.3 installed successfully.


Installation complete. If you want to use this version, type

nvm use 18.19.0

  1. 使用特定版本node:nvm use 18.19.0
C:\Users\kingwzun>nvm use 18.19.0
Now using node v18.19.0 (64-bit)
  1. 查看正在使用的 node: nvm current
C:\Users\kingwzun>nvm current
v18.19.0
  1. 卸载特定版本node:nvm uninstall 18.19.0

其他命令看官方教程吧(命令行输入nvm即可)

C:\Users\kingwzun>nvm

Running version 1.1.12.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm debug                    : Check the NVM4W process for known problems (troubleshooter).
  nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
                                 most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
                                 to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
                                 Add --insecure to the end of this command to bypass SSL validation of the remote download server.
  nvm list [available]         : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
  nvm on                       : Enable node.js version management.
  nvm off                      : Disable node.js version management.
  nvm proxy [url]              : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
                                 Set [url] to "none" to remove the proxy.
  nvm node_mirror [url]        : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
  nvm npm_mirror [url]         : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
  nvm uninstall <version>      : The version must be a specific version.
  nvm use [version] [arch]     : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
                                 "newest" is the latest installed version. Optionally specify 32/64bit architecture.
                                 nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
  nvm root [path]              : Set the directory where nvm should store different versions of node.js.
                                 If <path> is not set, the current root will be displayed.
  nvm [--]version              : Displays the current running version of nvm for Windows. Aliased as v.
posted @ 2023-12-17 16:30  kingwzun  阅读(314)  评论(1编辑  收藏  举报