Install multiple versions of node

1. Reasons for installing multiple versions of node:

  During the project development process, different projects use different nodejs versions, sometimes because the node version is too high or too low, resulting in an error; the
solution

  • Use nvm for management (this article uses this method)
  • Configure environment variables (if you understand environment variables, you can configure them yourself)

2. Use nvm for management

  1. The full name of nvm is Node Version Manager, which is a tool for managing NodeJS versions
  2. By default, nvm only supports Linux and OS X, and does not support Windows. You can use nvm-windows for Windows operating systems

1. Uninstall the installed nodeJS

  1. Click the start menu, find the nodejs folder, and click the arrow to uninstall it.
    insert image description here
  2. Detect whether nodejs still exists in the system,
      enter node -v in the cmd window to view
node -v

2. Installation and use of nvm

  1. nvm download
    download address
    insert image description here
    insert image description here

  2. Nvm installation
       creates two new folders under the specified file, one is used to store nvm installation files, and the other is used to store node files
    insert image description here

  3. Put the downloaded installation package into the nvm folder, unzip it, and install it

insert image description here

  1. Select the nvm installation path and click Next
    insert image description here
  2. Select the nodejs path
    insert image description here
  3. Click Install --> Click Finish to complete the installation.
  4. Confirm whether the installation is successful
    insert image description here
  5. nvm has been installed successfully
      If you have installed Taobao mirror, you need to complete the configuration of download mirror, open the settings.txt file under the nvm folder, and add the following code at the end of the
    insert image description here
      settings.txt file
node_mirror:https://npm.taobao.org/mirrors/node/
npm_mirror:https://npm.taobao.org/mirrors/npm/

insert image description here
  Where: root: nvm installation path; path: NodeJS shortcut path

  1. Install different versions of node and switch
      after NVM installation is successful, enter cmd with win + r to open a new cmd window, use the command "npm install version number" to install the specified version of NodeJS
    insert image description here
      After successful installation, a 16.14.1 folder appears in the nvm installation directory
    Install another version of NodeJS using "npm install version number" command again
    insert image description here
  2. nvm common commands
# 显示当前所使用的nvm版本号
nvm -v

# 查看可在线安装的node.js版本
nvm list available

# 查看已安装的node.js版本
nvm ls

# 显示当前正在使用的node.js版本
nvm current

# 安装最新稳定版
nvm install stable

# 在线安装指定版本的node.js,[version]为指定的版本号
nvm install [version]

# 卸载指定版本的node.js
nvm uninstall [version]

# 切换node.js版本
nvm use [version] 

# 验证nodejs是否安装成功
node -v

# 安装 yarn
npm install -g yarn
npm install -g yarn@[版本号]

Guess you like

Origin blog.csdn.net/bai_mi_student/article/details/128267495