Table of Contents
The reason for installing multiple versions of node:
Method 1: Use nvm for management
Introduction to NVM
Instructions before installation:
Uninstall the installed nodeJS
nvm installation and use
Installation and switching of different versions of node
方法二:通过配置环境变量(切换node时只需更改文件夹名称)
安装node及注意事项
配置环境变量
检查并安装多版本
node版本切换
Home Web Front-end JS Tutorial How to install and manage multiple versions of node? Method introduction

How to install and manage multiple versions of node? Method introduction

Jun 24, 2022 am 10:37 AM
nodejs​ node.js node

How to install and manage multiple versions of node? The following article will introduce you to the detailed operations of installing and switching multiple versions of node. I hope it will be helpful to you!

How to install and manage multiple versions of node? Method introduction

The reason for installing multiple versions of node:

During the project development process, different projects use nodejsDifferent versions may sometimes cause errors because the node version is too high or too low. How to install multiple versions of node in the same system? There are two ways. Read on and choose the one that suits you

Method 1: Use nvm for management

Introduction to NVM

NVM, the full name of Node Version Manager, is a tool for managing NodeJS versions.

NVM only supports Linux and OS X by default, and does not support Windows. There are 2 alternatives for Windows operating systems:

  • nvm-windows

  • nodist
    Here we only introduce the method of using nvm-windows to install and switch multiple versions of NodeJS.

Instructions before installation:

  • If you had a node environment before, you need to uninstall it cleanly
  • If you have installed node , enter nvm use <version number></version>, still invalid ("*" is not selected in front of the node version), you need to reinstall it on the
  • installation path Do not include Chinese characters or spaces, otherwise an error will occur

How to install and manage multiple versions of node? Method introduction

Uninstall the installed nodeJS

1. Click Start Menu, find the folder of nodejs, click the arrow to uninstall (note: you need to end the project using nodejs before doing this)

How to install and manage multiple versions of node? Method introduction

2. Check whether there is still a file in the system Nodejs exists

(1) Check in the start menu

(2) Enternode -v in the cmd window to check

nvm installation and use

  • nvm download

Installation package download address: https:// github.com/coreybutler/nvm-windows/releases
How to install and manage multiple versions of node? Method introduction

Note: Installation environmentwin10 system,64 bit

  • nvm installation(Note: It is best not to install on the C drive)
    (1) Create two new folders under the specified file, one with To store the nvm installation file, and another to store the node file
    How to install and manage multiple versions of node? Method introduction
    (2) Place the downloaded installation package into the nvm folder, unzip it, and install it.
    Note: During installation, select the newly created folder as the designated installation directory
    How to install and manage multiple versions of node? Method introduction
    (3) Select the nvm installation path and click Next
    How to install and manage multiple versions of node? Method introduction
    (4) Select nodejs path
    How to install and manage multiple versions of node? Method introduction
    (5) Click Install——>Click Finish to complete the installation.
    (6) Confirm whether the installation is successful
    Open CMD and enter the command nvm command. If the installation is successful, the following will be displayed
    How to install and manage multiple versions of node? Method introduction
    (7) nvm has been successfully installed.
    If you have installed Taobao image and need to complete the configuration of downloading the image, you can skip it if you don’t have any.
    Open the settings.txt file in the nvm folder and add the following code at the end (do not change, download node may report an error)
    How to install and manage multiple versions of node? Method introduction

arch: 64proxy:
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
Copy after login

Note:

arch: Windows operating system number
proxy: proxy, Taobao NodeJS image and NPM image

How to install and manage multiple versions of node? Method introduction
Note:

root: NVM installation path
path: NodeJS shortcut path

Installation and switching of different versions of node

1. After NVM is successfully installed, win r and enter cmd to open a new cmd window. You can view all available commands through the nvm -v command. .

C:\>nvm -v

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.</path></arch></version></version>
Copy after login

2、使用 nvm install 命令安装指定版本的NodeJS

C:\>nvm install v8.16.2
Downloading node.js version 8.16.2 (64-bit)...
Complete
Downloading npm version 6.4.1... Complete
Installing npm v6.4.1...

Installation complete. If you want to use this version, type

nvm use 8.16.2
Copy after login

3、安装成功后在 NVM 安装目录下出现一个 v8.16.2 文件夹,使用 nvm list 命令查看已安装 NodeJS 列表。

C:\>nvm list

     8.16.2
Copy after login

4、再次使用 nvm install 命令安装另一版本的 NodeJS

C:\>nvm install v12.8.0
Downloading node.js version 12.8.0 (64-bit)...
Complete
Creating C:\Dev\nvm\temp

Downloading npm version 6.10.2... Complete
Installing npm v6.10.2...

Installation complete. If you want to use this version, type

nvm use 12.8.0
Copy after login

5、使用nvm use 切换需要使用的 NodeJS 版本,切换成功后可以使用 node -vnpm -v 命令查看是否切换成功。

C:\>nvm use v8.16.2
Now using node v8.16.2 (64-bit)

C:\>node -v
v8.16.2

C:\>npm -v
6.4.1
Copy after login

这里需注意使用nvm use 时可能出现乱码的情况

C:\>nvm use v8.16.2
exit status 1: ��û���㹻��Ȩ��ִ�д˲�����
Copy after login

不要慌张,不要生气,这时候用重新打开一个以管理员身份运行cmd窗口就不会出现乱码的情况,使用nvm use 切换需要使用的 NodeJS 版本,使用nvm ls 查看所有安装的node版本,版本号前面带有*号的表示当前使用的NodeJS版本。

C:\Windows\system32>nvm use v8.16.2
Now using node v8.16.2 (64-bit)

C:\Windows\system32>nvm ls
    12.8.0
  * 8.16.2 (Currently using 64-bit executable)
Copy after login

6、这里是一些常用命令汇总:

nvm off                     // 禁用node.js版本管理(不卸载任何东西)
nvm on                      // 启用node.js版本管理
nvm install <version>       // 安装node.js的命名 version是版本号 例如:nvm install 8.12.0
nvm uninstall <version>     // 卸载node.js是的命令,卸载指定版本的nodejs,当安装失败时卸载使用
nvm ls                      // 显示所有安装的node.js版本
nvm list available          // 显示可以安装的所有node.js的版本
nvm use <version>           // 切换到使用指定的nodejs版本
nvm v                       // 显示nvm版本
nvm install stable          // 安装最新稳定版</version></version></version>
Copy after login

方法二:通过配置环境变量(切换node时只需更改文件夹名称)

安装node及注意事项

1、同样,如果之前有安装过node,为了避免不必要的麻烦,将其先卸载掉

注意:安装多个版本的node的时候一定要从低版本开始安装,如果你先安装高版本的话会出现许多问题,如果你已经安装啦,先卸载掉然后进行下面的步骤

2、在安装node之前,我先选择一个node安装目录,我要安装到D盘下,所以我在D盘中新建了一个NODE的目录,并且在里面创建了一个nodejs8的文件夹,因为我一会要在这个文件夹中安装8.16.2版本的node

How to install and manage multiple versions of node? Method introduction

3、开始安装

node版本可以去node中文网或者点击这里下载https://nodejs.org/

打开下载好的node8.16.2的安装包,一直点击下一步,直到出现安装路径,将安装路径切换为我们上面新建的nodejs8文件夹路径:D:\tools\NODE\nodejs8,然后一路下一步,直到安装成功

配置环境变量

在开始搜索框搜环境变量,注意这里选择编辑系统环境变量—>高级—>环境变量

How to install and manage multiple versions of node? Method introduction

How to install and manage multiple versions of node? Method introduction

在系统变量中点击新建,变量名:nodejs,变量值:D:\tools\NODE\nodejs(即上面存放node的文件夹,这里先去掉nodejs8后面的8)

How to install and manage multiple versions of node? Method introduction

How to install and manage multiple versions of node? Method introduction

点击确定后再系统变量中找到path 变量,选中后点击编辑,然后点击新建,将上面新建系统变量的变量名以%变量名%的形式加入,点击确定

How to install and manage multiple versions of node? Method introduction

这时候还不行,最关键的一点是:我们需要将一开始建的文件夹nodejs8重命名为nodejs

值得注意的是:这里将nodejs8重命名的一方面是为了与上面配置的环境变量中的变量名匹配(即使用此版本node),另一方面是为了更好的安装下一个版本(因为在安装完一个node版本之后如果文件名不修改的话,后面再安装其他版本的node时无论你安装到什么地方,都会把之前的那个覆盖掉)

How to install and manage multiple versions of node? Method introduction

检查并安装多版本

1、检查

重名名之后,然后win+R—>cmd,在命令窗口输入node -v查看node 版本,出现版本号说明第一个node版本安装成功

C:\>node -v
v8.16.2
Copy after login

2、安装下一个版本

由于上面已经将安装的node8.16.2版本的文件名重命名(防止覆盖),这时我们只需在同级目录下新建一个文件夹nodejs12,安装node12.8.0版本的node(方法同上面安装node8.16.2)
How to install and manage multiple versions of node? Method introduction

node版本切换

重点来了,在安装了多个版本的node的之后,在我们需要切换版本的时候,只需要将对应版本的文件夹重命名为nodejs即可

例如:我们先装了node8.16.2版本的(放在nodejs文件夹下)和node12.8.0版本的(放在nodejs12文件夹下),现在使用的node是8.16.2,那么要想切换至node12.8.0版本的node,只需更改文件名,将nodejs重命名为nodejs8,再将nodejs12重命名为nodejs即可,换句话说就是用哪个版本的node就将哪个版本的node文件夹重命名为nodejs
How to install and manage multiple versions of node? Method introduction
此时在打开命令行窗口,输入node -v检查node版本

C:\>node -v
v12.8.0
Copy after login

小伙伴儿们你们习惯使用哪个种方式呢?两种方式你们都学废了吗!评论区一起讨论一下吧!

更多node相关知识,请访问:nodejs 教程

The above is the detailed content of How to install and manage multiple versions of node? Method introduction. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed graphic explanation of the memory and GC of the Node V8 engine Detailed graphic explanation of the memory and GC of the Node V8 engine Mar 29, 2023 pm 06:02 PM

This article will give you an in-depth understanding of the memory and garbage collector (GC) of the NodeJS V8 engine. I hope it will be helpful to you!

An article about memory control in Node An article about memory control in Node Apr 26, 2023 pm 05:37 PM

The Node service built based on non-blocking and event-driven has the advantage of low memory consumption and is very suitable for handling massive network requests. Under the premise of massive requests, issues related to "memory control" need to be considered. 1. V8’s garbage collection mechanism and memory limitations Js is controlled by the garbage collection machine

How to use express to handle file upload in node project How to use express to handle file upload in node project Mar 28, 2023 pm 07:28 PM

How to handle file upload? The following article will introduce to you how to use express to handle file uploads in the node project. I hope it will be helpful to you!

Let's talk in depth about the File module in Node Let's talk in depth about the File module in Node Apr 24, 2023 pm 05:49 PM

The file module is an encapsulation of underlying file operations, such as file reading/writing/opening/closing/delete adding, etc. The biggest feature of the file module is that all methods provide two versions of **synchronous** and **asynchronous**, with Methods with the sync suffix are all synchronization methods, and those without are all heterogeneous methods.

An in-depth analysis of Node's process management tool 'pm2” An in-depth analysis of Node's process management tool 'pm2” Apr 03, 2023 pm 06:02 PM

This article will share with you Node's process management tool "pm2", and talk about why pm2 is needed, how to install and use pm2, I hope it will be helpful to everyone!

Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Mar 05, 2025 pm 05:57 PM

Detailed explanation and installation guide for PiNetwork nodes This article will introduce the PiNetwork ecosystem in detail - Pi nodes, a key role in the PiNetwork ecosystem, and provide complete steps for installation and configuration. After the launch of the PiNetwork blockchain test network, Pi nodes have become an important part of many pioneers actively participating in the testing, preparing for the upcoming main network release. If you don’t know PiNetwork yet, please refer to what is Picoin? What is the price for listing? Pi usage, mining and security analysis. What is PiNetwork? The PiNetwork project started in 2019 and owns its exclusive cryptocurrency Pi Coin. The project aims to create a one that everyone can participate

Let's talk about the event loop in Node Let's talk about the event loop in Node Apr 11, 2023 pm 07:08 PM

The event loop is a fundamental part of Node.js and enables asynchronous programming by ensuring that the main thread is not blocked. Understanding the event loop is crucial to building efficient applications. The following article will give you an in-depth understanding of the event loop in Node. I hope it will be helpful to you!

What should I do if node cannot use npm command? What should I do if node cannot use npm command? Feb 08, 2023 am 10:09 AM

The reason why node cannot use the npm command is because the environment variables are not configured correctly. The solution is: 1. Open "System Properties"; 2. Find "Environment Variables" -> "System Variables", and then edit the environment variables; 3. Find the location of nodejs folder; 4. Click "OK".

See all articles