利用nvm安装使用多版本nodejs

安装

  1. 下载地址 nvm-windows
    https://github.com/coreybutler/nvm-windows/releases/tag/1.1.7
  2. 卸载安装好的nodejs, 如果想继续使用nodejs原来的目录C:\Program Files\nodejs,需要删除文件夹C:\Program Files\nodejs
  3. 解压nvm-noinstall.zip, 到想要安装的目录
  4. 点击install.cmd 安装
    1. 自动生成环境变量,并且生成settings.txt文件在当前目录
    2. 修改settings.txt
      1. root: nvm安装目录
      2. path: nodejs文件夹映射目录
      3. 添加node和npm镜像,替换原有镜像,可以加快速度
        root: C:\MyApp\nvm  
        path: C:\Program Files\nodejs 
        arch: 64 
        proxy: none
        node_mirror: https://npm.taobao.org/mirrors/node/
        npm_mirror: https://npm.taobao.org/mirrors/npm/
  5. 把nvm安装目录加到环境变量path
  6. 打开cmd 运行 nvm 验证安装,安装成功会显示命令行提示

使用

显示可用node版本

nvm list available

显示已经安装的node版本

nvm ls

切换版本

nvm use 版本号
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.
posted @ 2021-06-03 23:23  白日梦想家Jarod  阅读(107)  评论(0)    收藏  举报