有时候,我们可能会根据不同情况使用不同版本的nodejs环境,nvm支持你在本机安装多个版本的nodejs,具体操作步骤如下:
1、卸载已安装的nodejs,注意把以下目录的文件也删除掉:
C:\Users\Administrator\AppData\Roaming\npm
C:\Users\Administrator\AppData\Roaming\npm-cache
C:\Program Files\nodejs
2、下载nvm-windows,选择nvm-setup.zip,并安装
3、测试是否安装成功,同时可以看到nvm的每个命令的用法
$ nvm -v
Running version 1.1.7.
Usage:
nvm arch : Show if node is running in 32 or 64 bit mode.
nvm install <version> [arch] : The version can be a node.js version or "latest" for the latest stable 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 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.
4、在国内访问npm源可能比较慢,可以配置成taobao镜像
nvm node_mirror https://npm.taobao.org/mirrors/node/
nvm npm_mirror https://npm.taobao.org/mirrors/npm/
5、安装某个版本的node,安装node的同时,npm也会被安装
$ nvm install 11.15.0
6、node安装完成,根据需要使用具体的node版本
$ nvm use 11.15.0
Now using node v11.15.0 (64-bit)
$ npm -v
6.7.0
$ node -v
v11.15.0