web前端技术

nodejs的管理工具nvm

2020-01-30  本文已影响0人  JyLie

title: nodejs的管理工具nvm

2020 新年,疫情形势让我内心姗姗来迟的平静下来,于是...发现个人电脑竟然还装在 nodejs 独立版本,所以...写下一篇笔记。

安装

安装注意事项:

windows 下 安装

下载地址:https://github.com/coreybutler/nvm-windows/releases

下载完成后解压下载的 zip,生成 nvm-setup.exe 文件并运行。

然后配置 nvm 安装地址位置 与 设置 node 的 symlink 文件夹位置(注意安装 nvm 与 node 的所在目录不能存在空格等非常规字符) 。

然后安装流程下一步即可完成安装

在显示安装成功后,打开 GIT 命令窗口输入 nvm 后,窗口显示有关 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.

修改代理

在你安装的目录下找到 settings.txt 文件,打开后加上

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

settings.txt 最终效果

root: D:\nvm
path: D:\nodejs

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

nvm Usage

使用

先查看当前版本列表:nvm list

接着查看线上版本:nvm list available

然后安装需求版本: nvm install 12.13.0

最后使用 nvm 指定 node 版本: nvm use 12.13.0

可能遇见问题

windows 上安装 nvm 后选择 node 版本出现 exit status 1...

问题:nvm install x.x.x 可以成功,但无法切换和使用

原因:我把 nvm 安装到了有空格的路径上(D:\Program Files),导致切换失败

解决:把 nvm 卸载重装到没有空格的路径上(例如:D:\nvm),即可解决问题

nvm 在 Cmder 中不生效

原因就不需要解析了

解决:重启电脑后 或者重启命令工具后,即会生效。

安装时出现 npm Download failed.

原因:

  1. 可能是 npm 镜像地址为国外,没有科学上网超时下载
  2. 可能设置淘宝镜像后,所下载 npm 版本(如:node:v12.13.1, npm:v6.12.1)在淘宝镜像不存在,因此需要手动安装

解决:

问题 1:只需设置淘宝镜像即可,看上文

问题 2 则需要如下步骤:

上一篇 下一篇

猜你喜欢

热点阅读