使用nvm安装管理node版本

16,599 阅读1分钟

nvm的安装

注意:如果本地已经安装了node,要先卸载node再安装nvm
安装地址:github.com/coreybutler…
window用户直接选择 nvm-setup.zip 下载安装

$ nvm -v //检查nvm是否安装成功
/*
Running version 1.1.7.

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.
*/

使用nvm安装node

$ nvm -h //查看nvm的指令
$ nvm list //查看本地已经安装的node版本列表
$ nvm list available //查看可以安装的node版本
$ nvm install latest //安装最新版本的node
$ nvm install [version][arch] //安装指定版本的node 例如:nvm install 10.16.3 安装node v10.16.3 arch表示电脑的位数 如果电脑需要安装32位的, 则运行:nvm install 10.16.3 32
$ nvm use [version] //使用node 例如:nvm use 10.16.3
$ nvm uninstall [version] //卸载node

检查node和npm是否可用

$ node -v //v10.16.3
$ npm -v //6.9.0

镜像设置

在使用nvm安装node的过程中如果速度太慢的话,可以设置改用淘宝的镜像地址
在nvm安装目录下的setting.txt文件中加入以下代码

node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

注意:如果安装过程中失败不行了,可以考虑一下重装。重装还是不行,那就直接百度吧。自己踩坑

nvm 更新

nvm 从1.1.8版本开始,提供了更新 nvm 应用程序,只需要下载运行该程序,就可以更新 nvm 版本

image.png

image.png