Windows 下安装 NVM

引言

NVM 官方版本并不支持 Windows,所以需要使用nvm-windows实现Windows下NVM安装。

使用前请确保已卸载现有的Node.js

下载

github地址:nvm-windows

下载免安装的文件包
file

解压后确保有如下的文件
file

安装

进入任意一个常用的盘符,创建为使用nvm准备的文件夹。

已在C盘下新建一个dev文件夹作为nvm的安装目录,后续安装阐述都以C:\dev作为nvm的安装目录。

C:\dev下新建一个文件夹,名为nvm
file
将解压后的文件都放入nvm文件夹内
file
nvm文件夹内新建settings.txt文件
file
编辑settings.txt文件,并保存

root:  C:\dev\nvm
path:  C:\dev\nodejs
arch: 64 
proxy: none

root 设置nvm应该存储不同版本的node.js的目录
path 对当前使用的node.js创建统一路径的快捷方式引用(此快捷方式由nvm自动创建,无需手动创建)
arch 操作系统位数,一般都是64位操作系统,如32位操作系统,则填写32位
proxy 设置代理用于nvm下载node.js安装包,一般留空,即none
其他配置项可以参考github上关于nvm-windows的文档说明

打开高级系统设置-高级-环境变量
file
在系统变量内增加NVM_HOME以及NVM_SYMLINK变量
file
并在Path内追加新增的两个变量
file
file

使用

使用nvm命令校验是否安装成功

C:\windows\system32>nvm

Running version 1.1.4.

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/npm/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.

如果仍然无法正常返回,请重新检查上述配置是否有误,或重启操作系统。

安装最新的LTS长久维护版本的 Node.js :

C:\windows\system32>nvm install 8.11.2

查看本地所有可以用的 Node.js 版本:

C:\windows\system32>nvm list

  * 8.11.2 (Currently using 64-bit executable)
    7.10.0
    6.10.3
    10.0.0

需要安装多个版本就执行多次nvm install versionNumber 命令

设置已经安装的Node.js版本为默认版本:

C:\windows\system32>nvm use 8.11.2

检查 Node.js 的版本:

C:\windows\system32>node -v
v8.11.2

由于npm原始源会请求国外服务器,对于国内的开发者着实不友好,推荐使用 NPM registry 管理工具切换 NPM 镜像源。
使用 NPM registry 管理工具切换 NPM 镜像源


版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证

sothx
讨论数量: 1
pardon110

直接用linux开发得了

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!