前言:

在Web前端项目开发过程中,由于各种前端框架、插件 以及 Nodejs、Npm 的飞速更新,在项目新开发 或 对老项目进行更新维护时,有些项目版本的配置 和 当前Node、Npm环境不匹配,导致运行报错,甚至都无法启动。


Nvm的出现就是为了解决以上问题的,Nvm是一个Node.js版本管理器 ,为了解决Node各种版本存在不兼容问题,Nvm其实是让你在同一台机器上根据需要,安装 或 切换项目所对应的Node版本来适配项目。


官网的提示:

Running version 1.1.11.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm debug                    : Check the NVM4W process for known problems (troubleshooter).
  nvm install <version> [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 <version>      : 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 <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.
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

1、NVM简介

在项目开发过程中,使用到vue框架技术,需要安装node下载项目依赖,但经常会遇到node版本不匹配而导致无法正常下载,重新安装node却又很麻烦。为解决以上问题,nvm:一款node的版本管理工具,能够管理node的安装和使用,使用简单,可下载指定node版本和切换使用不同版本,方便了node的使用。


2、NVM安装

下载:

发行版本下载:https://github.com/coreybutler/nvm-windows/releases

nvm的一些常用命令和安装_github

压缩版本下载:https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-setup.zip

nvm的一些常用命令和安装_sed_02


安装:

nvm的一些常用命令和安装_sed_03

如果之前安装的有node.js,则需要先卸载掉,

C:\Program Files (x86)\Nodejs

C:\Program Files\Nodejs

C:\Users{User}\AppData\Roaming\npm(或%appdata%\npm)

C:\Users{User}\AppData\Roaming\npm-cache(或%appdata%\npm-cache)


检查您的%PATH%环境变量以确保没有引用Nodejs或npm存在

然后再安装,选择nvm安装根路径,路径最好不要带中文

nvm的一些常用命令和安装_sed_04

指定nodejs的安装路径

nvm的一些常用命令和安装_sed_05

测试

打开命令行,输入nvm -v 可查看版本,即安装成功

nvm的一些常用命令和安装_github_06