gogoWebsite

nvm installation detailed tutorial (uninstall the old nodejs, install nvm, node, npm, cnpm, yarn and environment variable configuration)

Updated to 30 minutes ago

Article Catalog

  • I. Completely uninstall the old nodejs
    • 1, open the system's control panel, click Uninstall a program, uninstall nodejs
      • (1) Open your system's Control Panel and click Uninstall a program under Programs.
      • (2) Find, right-click on the drop-down box appears, point uninstallation
      • (3) Confirm the uninstallation pop-up window, click Yes and wait for the uninstallation to complete.
    • 2. Delete the installation directory of node
    • 3. Find out if the .npmrc file exists, and delete it if it does.
    • 4. Check the following files one by one to see if they exist, and delete them if they do.
    • 5, open the system settings, check the system environment variables, node-related configuration are deleted!
    • 6. Check if the uninstallation is successful
    • 7, finally, it is recommended to restart the computer
  • II. Installation of nvm
    • 1. Download NVM
    • 2、Double-click the downloaded file to start installation
    • 3, select I accept, and then click next
    • 4, select the NVM installation path, the path name should not have spaces, and then click next
    • 5, the installation path, and then click next
    • 6. Click Install
    • 7, click Finish, complete the installation
  • Third, nvm modify the mirror source
  • Fourth, nvm common commands
  • V. nvm configuration environment variables
  • VI. Installation of nodejs and environment variable configuration
    • 1. Install node via nvm
    • 2, node environment variable configuration
      • (1) Configure globally installed module paths and cache paths
      • (2) Setting user variables
      • (3) Setting system variables
    • 3. Testing
    • 4, set Taobao's mirror and view
  • VII. Global installation of cnpm
  • VIII. Global installation of yarn
  • IX. The author's installation directory structure


Attention:
1. Before installing nvm you need toUninstall the previous nodejsand also remove the previous environment variable configurations, otherwise you will get some strange problems!
2. nvm installation pathNo Chinese characters or spacesOtherwise, switching the node version later in cmd will result in a garbled code

I. Completely uninstall the old nodejs

reference articleNode uninstallation step by step

1, open the system's control panel, click Uninstall a program, uninstall nodejs

(1) Open your system's Control Panel and click Uninstall a program under Programs.

在这里插入图片描述

(2) Find, right-click on the drop-down box appears, point uninstallation

在这里插入图片描述

(3) Confirm the uninstallation pop-up window, click Yes and wait for the uninstallation to complete.

在这里插入图片描述

2. Delete the installation directory of node

The installation directory defaults toC:\Program Files\nodejsMy installer chose to install mine in theD:\Program Files\nodejs

Check if there are node files under this pathIf you uninstall node from the control panel, the node files will be deleted automatically.Delete it manually if it's still there, ignore it if you don't have it.

在这里插入图片描述

3. Find out if the .npmrc file exists, and delete it if it does.

.npmrcDefaults to theC:\User\User Name

.node_repl_historyDelete it if it exists as well, ignore it if it doesn't.

在这里插入图片描述

4. Check the following files one by one to see if they exist, and delete them if they do.

  • C:\Program Files (x86)\Nodejs
  • C:\Program Files\Nodejs
  • C:\Users\User Name\AppData\Roaming\npm
  • C:\Users\User Name\AppData\Roaming\npm-cache
  • C:\Users\Username\AppData\Local\npm-cache

5, open the system settings, check the system environment variables, node-related configuration are deleted!

  • Generally, the system will automatically delete the node environment variables, you can not care about this step
  • The way the environment variable is opened:My Computer-> Properties-> Advanced System Settings-> Environment Variables->.
  • deleteuser variablecap (a poem)system variable(used form a nominal expression)NODE_PATH up toPath The relevant node in theDon't take the wholepathdeleteIf you click Edit, just delete the node-related ones; if you make a mistake, click theabolishClose the pop-up window will not be saved successfully, if the hand accidentally deleted, but also clicked on therecognizebutton, then there is nothing the author can do)
  • Confirmation of deletionAfter that, click on therecognizeClose, otherwise there may be a deletion failure problem
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

6. Check if the uninstallation is successful

From the keyboard, presswin + R Inputcmd , and then hit enter and type in the command linenode -v npm -vThe following figure indicates that the uninstallation was successful.

,在这里插入图片描述
在这里插入图片描述

7, finally, it is recommended to restart the computer

II. Installation of nvm

reference articlenvm-Download, Installation, Use (Updated 2023/07/12) Install nvm and use nvm to install nodejs and configure environment variables.

1. Download NVM

  • Address:/coreybutler/nvm-windows/releases
  • strike (on the keyboard)Download

在这里插入图片描述

2、Double-click the downloaded file to start installation

在这里插入图片描述

3, select I accept, and then click next

在这里插入图片描述

4, select the NVM installation path, the path name should not have spaces, and then click next

在这里插入图片描述

5, the installation path, and then click next

在这里插入图片描述

6. Click Install

在这里插入图片描述

7, click Finish, complete the installation

在这里插入图片描述

Third, nvm modify the mirror source

reference articlenvm download, nvm installation, nvm modification mirror source, nvm use.

  • win + R Inputcmd After Enter, at the command line, typenvm root command, which canCheck the root path of the nvm installationIt's in that folder.

在这里插入图片描述

  • In the file manager address barimportationrootaddressFindfile and open it

在这里插入图片描述

  • Copy and paste the following code as shown. Save to complete the nvm source modification.
node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror:  https://npmmirror.com/mirrors/npm/

在这里插入图片描述

Fourth, nvm common commands

reference articlenvm download, nvm installation, nvm modification mirror source, nvm use.

  • nvm install <version>: Install the specified version of .
  • nvm use <version>: Switch to the specified version of .
  • nvm ls: Lists all installed versions.
  • nvm alias <name> <version>: Create an alias for the specified version.
  • nvm run <version> <script>: Runs the script under the specified version.
  • nvm current: Displays the version currently in use.
  • nvm uninstall <version>: Uninstall the specified version of .

V. nvm configuration environment variables

reference articleInstall nvm and use nvm to install nodejs and configure environment variables.

  • The way the environment variable is opened:My Computer-> Properties-> Advanced System Settings-> Environment Variables->.
  • Verify consistency with the following configuration (default nvm will be generated automatically after a successful nvm installation)

在这里插入图片描述

  • win + R Inputcmd After Enter, at the command line, typenvm -v command, which returns the version number, proving that the configuration was successful.

在这里插入图片描述

VI. Installation of nodejs and environment variable configuration

reference articleInstall nvm and use nvm to install nodejs and configure environment variables.

1. Install node via nvm

  • Check out the latest batch of versions (version numbers: even numbers are absolutely stable versions, base numbers are not necessarily stable versions)
  • nvm list available

在这里插入图片描述

  • Installs the specified version:nvm install 10.23.0
  • View all versions installed:nvm list maybe nvm ls
  • Enter or switch versions:nvm use 18.15.0

在这里插入图片描述

  • After successful installation, the corresponding folder will be formed, as shown in the following figure

在这里插入图片描述

  • Check if the installation was successful:node -v Check out the version of node,npm -v Check the version of npm

在这里插入图片描述

2, node environment variable configuration

(1) Configure globally installed module paths and cache paths

  • First in the NVM installation directoryCreate two new foldersnode_globalcap (a poem)node_cache

在这里插入图片描述

  • After creating the two folders, enter the following commands in the cmd window (the two paths are the paths to the two folders)
npm config set prefix "D:\Programs\nvm\node_global"
npm config set cache "D:\Programs\nvm\node_cache"

在这里插入图片描述

(2) Setting user variables

  • The path variable in [User Variables].%NVM_HOME% cap (a poem)%NVM_SYMLINK% Theoretically, it is automatically generated after nvm is successfully installed. If not, create a new one in.
  • If there isC:\Users\User Name\AppData\Roaming\npm, then change it toD:\Programs\nvm\node_global(where you just created the node_global folder), if you don't have it, create it yourself.D:\Programs\nvm\node_globalIn short, it's guaranteed to have what's in the following pictures

在这里插入图片描述

(3) Setting system variables

  • The path variable is set as in the user variable.

在这里插入图片描述

  • New Environment VariablesNODE_PATHThe value isD:\Programs\nvm\node_global\node_moduleswhichD:\Programs\nvm\node_global\node_modulesis the global module installation path folder created above

在这里插入图片描述
在这里插入图片描述

3. Testing

  • Install the most commonly used express modules globally for testing
  • npm install express -g
  • Upon completion you will get aexpressdocuments

在这里插入图片描述
在这里插入图片描述

4, set Taobao's mirror and view

npm config set registry https:///
 
npm config get registry

在这里插入图片描述

VII. Global installation of cnpm

reference articleManaging npm and cnpm and yarn commands in node based on nvm.

  • cnpm itself is domestic, so there's no need to configure mirrors.
  • cnpm installation [the example in the picture is the old address, not updated, copy the code below]
npm install -g cnpm --registry=https:///

maybe

npm install -g cnpm
  • View cnpm version
cnpm -v
 
npm list cnpm -g

在这里插入图片描述

VIII. Global installation of yarn

reference articleManaging npm and cnpm and yarn commands in node based on nvm.

  • Yarn Installation
npm install yarn -g 

在这里插入图片描述

  • Set up Taobao mirrors and view
// Viewing Mirrors
yarn config get registry
// Modify the image
yarn config set registry https://registry.npmmirror.com

在这里插入图片描述

IX. The author's installation directory structure

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述