nvm installs and configures environment variables Use nvm to install and switch nodejs

Table of contents

Chapter 1 Preparations

1.1 uninstall nodejs

1.2 install nvm

Chapter 2 nvm environment configuration

Chapter 3 nodejs installation and environment configuration

3.1 Know how to use nvm common commands

3.2 nodejs installation

3.3 node environment configuration

3.4 Problems encountered


Chapter 1 Preparations

1.1 uninstall nodejs

  • Find the path of your corresponding nodejs file
where node

  • Uninstall nodejs through the control panel and make sure that no nodejs remains

  •  Check to see if the file is empty

 

1.2 install nvm

  • Download nvm, we download the installation package

Releases · coreybutler/nvm-windows · GitHub

  •  Modify the file path, not in English

  •  Create another nodejs folder under D:\nvm, and then modify the installation file path

  • Then continue to the next step, the installation is complete
  • Directory after installation:

Chapter 2 nvm environment configuration

  • It should be noted here that after nvm is installed, two lines of commands should be added to setting.txt in the root directory:
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

Purpose: Solve the error reporting when downloading a lower version of node (or there is no node version in the nvm list) and the setting of the corresponding npm version download error report 

  • Environment variable configuration (nvm will configure itself after installation, just confirm it)

(1) User environment

 (2) System environment

  • Remember to make sure that nvm is installed successfully
nvm -v

Chapter 3 nodejs installation and environment configuration

3.1 Know how to use nvm common commands

//1、版本管理
nvm on  //开启node.js版本管理。
nvm off  //关闭node.js版本管理。

//2、常用命令
nvm list available  //显示所有可以下载的版本
nvm install node版本号   //安装对应版本的node
nvm ls  //查看已安装的node版本列表
nvm use node版本号  //切换到对应版本的nodejs
nvm uninstall node版本号  //卸载到对应版本的node

//3、按钮查看
nvm --help //显示命令行帮助信息

3.2 nodejs installation

  • After the nvm environment is configured, use nvm to install nodejs

nodejs official website: download | Node.js Chinese website

View all nodejs version numbers official website: Previous Releases | Node.js

Note: If you don’t have the version you want when vnm ls, then go to the above two URLs to check the version number needed for nvm download; if you want to install nodejs independently, please go to the following article

Node detailed installation tutorial and Vue scaffolding construction_node scaffolding installation_❆VE❆'s Blog-CSDN Blog

  • installation steps

-- 1. Enter the command nvm list available to display all nodejs versions

  -- 2. Install the desired node version number (there may be a problem with the installation here, which will be explained later), taking the displayed version as an example, the command: nvm install 16.20.0

 It means that the node version of 16.20.0 has been successfully downloaded, and the corresponding npm has also been successfully installed!

-- 3. Check the installed nodejs version, command: nvm ls 

-- 4. Switch the desired node version, command: nvm use 16.20.0 (corresponding node version package)

 

-- 5. Check the version of node and npm through node -v and npm -v to determine whether the switch is successful

3.3 node environment configuration

Similar to the article, here I do the process again:

Node detailed installation tutorial and Vue scaffolding construction_node scaffolding installation_❆VE❆'s Blog-CSDN Blog

  • Create two new folders node_cache and node_global in the corresponding directory

  •  After creating the two folders, enter the following command in the cmd window (the two paths are the paths of the two folders):
npm config set prefix "D:\nvm\nodejs\node_global"
npm config set cache "D:\nvm\nodejs\node_cache"
  • Next, set the computer environment variables, right-click "My Computer" => Properties => Advanced System Settings => Environment Variables to enter the following environment variable dialog box.
  • Create a new environment variable NODE_PATH in [System Variables] , with a value of D:\nvm\nodejs\node_global, where D:\nvm\nodejs\node_global is the global module installation path folder created above :

  •  Modify the path variable in [User Variables] , and change C:\Users\JW\AppData\Roaming\npm to D:\nvm\nodejs\node_global

  •  After clicking OK, the configuration is complete.
  • To test whether the configuration is successful, enter the following in the cmd window to specify the global installation of yarn
npm install -g yarn     # -g表示是全局安装
  • Successful installation view

  • For the yarn command: it needs to be configured globally before it can be used. Configure it in [User Variables]

 

  •  Check whether the configuration is successful:

3.4 Problems encountered

  • When the installed node is not the displayed node version:

Error while downloading https://github.com/npm/cli/archive/v6.14.18.zip , the reason for the error is: an error occurred when downloading the corresponding npm version, and we need to download it from github... In fact, we only need to configure those two in the setting path just fine

The solution is in Chapter 2

Guess you like

Origin blog.csdn.net/qq_45796592/article/details/130747095