在windows中安装nvm,并使用nvm管理node版本

最近想使用nvm管理node环境,安装后发现使用nvm切换node版本无效,一不小心又把windows的node环境搞挂了,于是卸载,还原。今天有时间,于是再次尝试安装nvm来管理node,并记录下来分享和备用。

一、nvm的安装

  1. 下载nvm
    https://github.com/coreybutler/nvm-windows/releases下载nvm-windows
    如图

    选择下载

  2. 打开下载文件安装nvm,选择nvm安装目录


    选择nvm安装目录
  3. 选择node关联文件夹,选择之前node的安装目录


    选择node关联文件夹
  4. 选择使用nvm管理已经安装的node


    选择使用nvm管理已经安装的node
  5. 安装完毕


    image.png

二、nvm的使用

  1. 查看nvm版本
nvm version
1.1.7
  1. 使用nvm安装node
    以12.3.0版本为例
nvm install 12.3.0
  1. 查看安装的node
nvm list 或 nvm ls

    12.3.0
  * 10.15.3 (Currently using 64-bit executable)
  1. 使用nvm切换node版本
    以12.3.0为例
# 切换到12.3.0
nvm use 12.3.0
Now using node v12.3.0 (64-bit)

# 查看node版本
node -v
v12.3.0
  1. nvm的更多用法
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.

推荐阅读更多精彩内容