使用nvm管理node版本

node 历史版本历史遗留问题越来越多, 导致本地测试开发只用一个node版本变得不可能
使用nvm node管理工具自动管理会更方便.
为了将node版本全权交给nvm, 需要删除本地已手动安装的node, 然后使用nvm命令行安装

安装

https://github.com/coreybutler/nvm-windows/releases/
注意: 安装目录不要有中文,以及空格,否则容易导致命令不好使

控制台中输入 nvm , 打印如下则表示安装成功

Running version 1.1.9.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm install  [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       : 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  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  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安装目录下找到 settings.txt文件, 填入镜像源

# 安装目录不要有中文,以及空格,否则容易导致命令不好使
root: D:\soft\nvm
path: D:\soft\nvm\nodejs
# 以下是镜像源
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

安装node

nvm install xx.xx.xx

去中文官网查看 http://nodejs.cn/ 版本
例如最新稳定版安装16.16.0

nvm install 16.16.0

选择使用node的版本,如下

nvm use 16.16.0

查看当前使用的版本

nvm current

列出已安装的可使用的版本

nvm ls

其他命令可自行查看

你可能感兴趣的:(使用nvm管理node版本)