利用nvm进行管理
安装前须知:
- 之前有node环境的需要要卸载干净
- 如果安装完node后,输入
nvm use <版本号>
,仍无效(node版本前面都没有选中的"*"
),需重新安装 - 安装路径上不要有中文字符或者空格,否则会出现错误
卸载node
- 打开菜单,找到node 文件,点击箭头指定地方,进行删除
- 卸载成功后在cmd 用
node -v
查看
下载nvm路径
nvm 安装
-
选择nvm-setup.zip 文件下载
-
蓝色框可自定义文件
- 点击 Install——>点击 Finish,安装完成
- 确认是否安装成功
到此nvm已经安装成功
如果有安装淘宝镜像的需完成下载镜像的配置,没有可跳过 - 打开nvm文件夹下的
settings.txt
文件,在最后添加以下代码(不改,下载node可能会报错)
- 在
settings.txt
文件加上
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
node 的不同版本安装及切换
- NVM 安装成功后,win + r 输入cmd 新开cmd窗口,可以通过 nvm -v 命令查看所有可用的命令。
C:\>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.
- 使用 nvm install <版本号>命令安装指定版本的NodeJS
C:\>nvm install v8.16.2
Downloading node.js version 8.16.2 (64-bit)...
Complete
Downloading npm version 6.4.1... Complete
Installing npm v6.4.1...
Installation complete. If you want to use this version, type
nvm use 8.16.2
- 安装成功后在 NVM 安装目录下出现一个 v8.16.2 文件夹,这时可以尝试在上面使用 nvm list 命令查看已安装 NodeJS 列表
C:\>nvm list
8.16.2
- 使用nvm use <版本号> 切换需要使用的 NodeJS 版本,切换成功后可以使用 node -v 和 npm -v 命令查看是否切换成功。
C:\>nvm use v8.16.2
Now using node v8.16.2 (64-bit)
C:\>node -v
v8.16.2
C:\>npm -v
6.4.1
- 这里是一些常用命令汇总:
nvm off // 禁用node.js版本管理(不卸载任何东西)
nvm on // 启用node.js版本管理
nvm install <version> // 安装node.js的命名 version是版本号 例如:nvm install 8.12.0
nvm uninstall <version> // 卸载node.js是的命令,卸载指定版本的nodejs,当安装失败时卸载使用
nvm ls // 显示所有安装的node.js版本
nvm list available // 显示可以安装的所有node.js的版本
nvm use <version> // 切换到使用指定的nodejs版本
nvm v // 显示nvm版本
nvm install stable // 安装最新稳定版