- node version manager(node版本管理工具)
- 通过将多个node 版本安装在指定路径,然后通过 nvm 命令切换时,就会切换我们环境变量中 node 命令指定的实际执行的软件路径。
- 使用场景:比如我们手上同时在做好几个项目,这些项目的需求都不太一样,导致了这些个项目需要依赖的nodejs版本也不同,这种情况下,我们就可以通过nvm来切换nodejs的版本,而不需要频繁地下载/卸载不同版本的nodejs来满足当前项目的要求
windows系统下的nvm 安装
1. 下载
链接:https://github.com/coreybutler/nvm-windows/releases
可下载以下版本:
nvm-noinstall.zip:绿色免安装版,但使用时需要进行配置。
nvm-setup.zip:安装版,推荐使用
2. 安装(nvm-setup)
- 这里是列表文本双击文件nvm-setup.exe

- 选择nvm安装路径

*遇坑警告!!!!!*
这里我一开始选择的路径为C:\Program Files\nvm
在安装完成后,执行nvm use 14.5.0的时候,出现了:exit code 1:‘D:\Program’ #%$#^%$^%&%&@#
的问题(后面这些符号表示当时报错时候的乱码……)
查阅了一些前人的经验后得知,问题的原因是Program Files这个文件名中含有空格@_@
所以,各位在选择文件夹的时候,需要注意,文件夹名不要出现中文和空格。
- 选择nodeks安装路径

- 确认安装


- 检查是否安装成功
打开CMD,输入nvm,安装成功则会如下图所示,它会显示出当前nvm版本以及nvm的命令:
C:\Users\LittleMo>nvm
Running version 1.1.11.
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配置文件(可选)
nvm安装完成后,打开nvm安装目录下的settings.txt文件:
root: D:\nvm
path: D:\nvm\nodejs
arch: 64
proxy: none
node_mirror: http://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/3. 使用nvm
nvm list 命令 - 显示版本列表
nvm list // 显示已安装的版本(同 nvm list installed) nvm list installed // 显示已安装的版本 nvm list available // 显示所有可以下载的版本nvm install 命令 - 安装指定版本nodejs
nvm install 14.5.0 // 安装14.5.0版本node nvm install latest // 安装最新版本nodenvm use 命令 - 使用指定版本node
nvm use 14.5.0 // 使用14.5.0版本nodenvm uninstall 命令 - 卸载指定版本 node
nvm uninstall 14.5.0 // 卸载14.5.0版本node
遇坑警告!!!!!
在运行nvm install的时候,有可能会出现无权限安装的问题,如果遇到此问题,请 以管理员身份运行cmd。
4. 其他命令
nvm arch:显示node是运行在32位还是64位系统上的nvm on:开启nodejs版本管理nvm off:关闭nodejs版本管理nvm proxy [url]:设置下载代理。不加可选参数url,显示当前代理。将url设置为none则移除代理。nvm node_mirror [url]:设置node镜像。默认是https://nodejs.org/dist/。如果不写url,则使用默认url。设置后可至安装目录settings.txt文件查看,也可直接在该文件操作。nvm npm_mirror [url]:设置npm镜像。https://github.com/npm/cli/archive/。如果不写url,则使用默认url。设置后可至安装目录settings.txt文件查看,也可直接在该文件操作。nvm root [path]:设置存储不同版本node的目录。如果未设置,默认使用当前目录。nvm version:显示nvm版本。version可简化为v。
5. 国内镜像
阿里云
nvm npm_mirror https://npmmirror.com/mirrors/npm/
nvm node_mirror https://npmmirror.com/mirrors/node/腾讯云
nvm npm_mirror http://mirrors.cloud.tencent.com/npm/
nvm node_mirror http://mirrors.cloud.tencent.com/nodejs-release/

发表评论 取消回复