在不同的项目中有时候依赖的node版本不一致,需要安装多个node版本依赖进行管理,这时候就需要使用nvm进行node版本管理操作。

  1. 首先进行nvm包的下载,找到下面这个进行下载下载地址
    在这里插入图片描述

  2. 下载完成之后进行鼠标双击打开安装操作,直接nextnext操作。下面这一步一定要注意,有些文中说安装之前必须卸载之前安装的node,我安装时并没有卸载node,这一步很关键,就是安装nvm时选择安装node路径一定是你已经安装的node的文件路径。在后面安装进程中会询问是否把之前安装的node模块加入nvm管理之中,点击yes就可以了。
    在这里插入图片描述
    安装完成之后在cmd命令行窗口进行nvm -v 操作会提示安装版本以及一大堆提示指令说明安装成功了。

  3. 安装成功以后我们就可以使用nvm安装node的其他版本,常见的指令如下:

 nvm arch                     : Show if node is running in 32 or 64 bit mode.
 nvm current                  : Display active version.
 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 use [version]切换版本的过程中发现窗口提示错误如下:
在这里插入图片描述
那么就需要进行管理员权限运行cmd窗口,右键选择,然后进行同样的命令执行操作。
在这里插入图片描述

$  nvm use [version]

注意使用nvm切换node版本使用完毕之后,启动其他项目有可能需要将node版本切换回去。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐