安装前清理原有的 node,环境变量,缓存(e.g. "C:Users<user>AppDataRoaming pm*")
保存配置(e.g. C:Users<user>.npmrc & C:Users<user>AppDataRoaming pmetc.npmrc)
下载(有安装版与解压版,以解压为例)
https://github.com/coreybutler/nvm-windows/releases
解压后执行管理员方式执行 install.cmd,输入 NVM 解压的绝对路径即可。
脚本主要就是设置了环境变量,也可自己设置。设置完后会在 shell 的所在路径生成一个 settings.txt,记录路径。
NVM_HOME D:PcAPPMVM NVM_SYMLINK C:Program Files odejs Path %NVM_HOME%;%NVM_SYMLINK%
settings.txt
root: D:PcAPPMVM arch: 64 proxy: none originalpath: . originalversion: node_mirror: https://npm.taobao.org/mirrors/node/ npm_mirror: https://npm.taobao.org/mirrors/npm/
不设置的话可能会报如下错误
ERROR open settings.txt: The system cannot find the file specified.
然后就可以使用了,在使用之前最好设置一下镜像源
nvm node_mirror https://npm.taobao.org/mirrors/node/ nvm npm_mirror https://npm.taobao.org/mirrors/npm/
常用命令
NVM for Windows is a command line tool. Simply type nvm
in the console for help. The basic commands are:
nvm arch [32|64]
: Show if node is running in 32 or 64 bit mode. Specify 32 or 64 to override the default architecture.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.nvm list [available]
: List the node.js installations. Typeavailable
at the end to show a list of versions available for download.nvm on
: Enable node.js version management.nvm off
: Disable node.js version management (does not uninstall anything).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 uninstall <version>
: Uninstall 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 based on the value supplied to<arch>
. For information about usinguse
in a specific directory (or using.nvmrc
), please refer to issue #16.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.nvm node_mirror <node_mirror_url>
: Set the node mirror.People in China can use https://npm.taobao.org/mirrors/node/nvm npm_mirror <npm_mirror_url>
: Set the npm mirror.People in China can use https://npm.taobao.org/mirrors/npm/
# 显示已安装 node 版本 nvm ls # 显示线上所有版本 nvm ls available # 显示 nvm 版本 nvm # 安装指定版本 nvm install 14.6.0 # 安装最新稳定版 nvm install latest # 使用指定版本(切换版本后,全局安装的需要重新安装) nvm use 14.6.0
配置 npm 全局安装路径
npm config set prefix "D: odejs pm-global"
在 C:Users用户名 下会生成 .npmrc 文件,可以看到:prefix=D: odejs pm-global
设置 npm 源
npm config set registry https://registry.npm.taobao.org