Node【工具 01】Node Version Manager nvm安装使用(Node.js版本管理工具)

简介: Node【工具 01】Node Version Manager nvm安装使用(Node.js版本管理工具)

1.介绍

非专业前端开发工程师在构建项目时遇到如下问题:

ERROR: This version of pnpm requires at least Node.js v16.14
The current version of Node.js is v14.17.0
Visit https://r.pnpm.io/comp to see the list of past pnpm versions with respective Node.js version support.

懵了,一台电脑安装多个JDK版本我们是常遇到的,前端就不知道怎么处理了,幸亏有了nvm。使用它可以简单解决上面的问题:

nvm install 16.14.0

nvm 是 Node.js 的版本管理工具(Node Version Manager)。它允许在同一台计算机上同时安装和管理多个 Node.js 版本。这对于开发人员和项目来说是非常有用的,因为不同的项目可能需要不同的 Node.js 版本来运行。以下是 nvm 的一些主要用途:

  1. 多版本支持: 允许你在同一台计算机上安装多个 Node.js 版本,而不会互相干扰。这对于不同项目使用不同的 Node.js 版本时非常重要。
  2. 版本切换: 允许你在不同项目之间切换 Node.js 版本。通过简单的命令,你可以轻松切换全局 Node.js 版本或在特定项目目录中使用特定版本。
  3. 便于测试: 如果你的应用程序或库需要在不同版本的 Node.js 上进行测试,nvm 可以使得这个过程更加简便。你可以在不同版本的 Node.js 上运行测试套件,确保你的代码在各个环境中都能正常工作。
  4. 升级和回退: 通过 nvm,你可以轻松升级到最新的 Node.js 版本,或者在需要时回退到旧版本。这对于确保应用程序在新版 Node.js 中正常运行,同时避免可能的兼容性问题非常有帮助。

使用 nvm,可以通过简单的命令行操作轻松管理 Node.js 版本,而无需手动下载、安装或卸载。这对于大多数 Node.js 开发者来说是一个非常方便的工具。

2.命令使用

2.1 安装

  • Windows直接下载nvm-setup.exe双击即可安装。
C:\Users\Administrator>nvm -v
1.1.10

2.2 查看可用的版本

nvm ls

2.3 安装指定版本的 Node.js

nvm install 16.14.0

2.4切换版本

nvm use 16.14.0

2.5 卸载指定版本的 Node.js

nvm uninstall 14.17.5

2.6 更多命令小伙伴们可以自行探索

Running version 1.1.10.
Usage:
  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  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.

3.问题

3.1 无法切换版本

  • 原因:安装nvm时管理的nodejs目录跟之前安装的目录不一致。
  • 处理:删除之前的nodejs目录,使用nvm重新安装。
目录
相关文章
|
8天前
|
存储 JavaScript 前端开发
Node 版本控制工具 NVM 的安装和使用(Windows)
本文介绍了NVM(Node Version Manager)的Windows版本——NVM for Windows的安装和使用方法,包括如何安装Node.js的特定版本、列出已安装版本、切换使用不同版本的Node.js,以及其他常用命令,以实现在Windows系统上对Node.js版本的便捷管理。
Node 版本控制工具 NVM 的安装和使用(Windows)
|
20天前
|
JavaScript Linux 开发者
一个用于管理多个 Node.js 版本的安装和切换开源工具
【9月更文挑战第14天】nvm(Node Version Manager)是一个开源工具,用于便捷地管理多个 Node.js 版本。其特点包括:版本安装便捷,支持 LTS 和最新版本;版本切换简单,不影响开发流程;多平台支持,包括 Windows、macOS 和 Linux;社区活跃,持续更新。通过 nvm,开发者可以轻松安装、切换和管理不同项目的 Node.js 版本,提高开发效率。
|
2月前
|
JavaScript 小程序 Java
【工具】用nvm管理nodejs版本切换,真香!
本文详细介绍了如何使用 nvm(node.js 版本管理工具)解决在不同项目间频繁切换 Node.js 版本的问题。通过实例展示了 A、B 两个项目分别依赖 v14.19.1 和 v16.15.0 版本时的解决方案,并提供了 nvm 的下载、安装及常用命令等实用信息,帮助读者轻松管理 Node.js 版本。文章还包括了卸载已安装的 Node.js、配置环境变量等步骤,确保切换顺畅无阻。
61 0
【工具】用nvm管理nodejs版本切换,真香!
|
2月前
|
JavaScript IDE 前端开发
前端开发工具配置 nodejs & git & IDE
前端开发工具配置 nodejs & git & IDE
|
2月前
|
JavaScript 前端开发 Shell
mac和windows上安装nvm管理node版本
NVM(Node Version Manager)是前端开发者常用的命令行工具,用于管理计算机上的不同Node.js版本。通过NVM,开发者可以轻松地在多个项目间切换所需的Node.js版本。在Mac上,可以通过cURL或Wget下载安装脚本,或使用包管理工具brew安装。安装后需配置环境变量以识别NVM命令。Windows用户则可通过专用的nvm-windows安装程序完成安装。常用命令包括安装、卸载特定版本、列出已安装版本等。
133 0
|
3月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的客户关系管理系统附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的客户关系管理系统附带文章源码部署视频讲解等
78 2
|
3月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的宠物援助平台附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的宠物援助平台附带文章源码部署视频讲解等
68 4
|
3月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的宠物交易平台附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的宠物交易平台附带文章源码部署视频讲解等
60 4
|
3月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的大学生入伍人员管理系统附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的大学生入伍人员管理系统附带文章源码部署视频讲解等
78 4
|
3月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的小区物流配送系统附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的小区物流配送系统附带文章源码部署视频讲解等
78 3