一些老的项目需要用到 node.js v16版本,新的项目又要求必须大于v18或v20,这就需要一个 node.js 的版本管理工具,在windows下可以安装 nvm-windows。

nvm-windows 项目地址:https://github.com/coreybutler/nvm-windows,可以从 Releases 页面选择最新版本下载,如下图所示:

Win11 安装 nvm-程序旅途

准备工作

如果已经安装过 node.js,建议先卸载掉,而且要把安装目录的 nodejs 文件夹删掉。 完成这两步,能够减少很多不必要的麻烦。

安装nvm-windows

双击 nvm-setup.exe开始安装,按照步骤提示操作即可。

安装完成后,打开window终端

Win11 安装 nvm-程序旅途

输入 nvm -v

Win11 安装 nvm-程序旅途

打印出 1.1.12,说明安装成功了。

nvm 常用命令

nvm -h 可以查看 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.

以下是一些常用的

nvm install 版本号/latest/lts,我一般都是先 nvm install lts,然后再安装特定的老版本,比如 nvm install 16.20.2

nvm list,查看已经安装了那些版本的node.js

nvm use 版本号/latest/lts,是使用哪个版本的node.js

Win11 安装 nvm-程序旅途