node version manager nvm

1. Uninstall node

  1. Open the cmd command line window, enter npm cache clean --force and press Enter to execute
    insert image description here

  2. Open the control panel and uninstall Node.js in the control panel
    insert image description here

Two, nvm download

  1. Nvm is also called node.js version management in English, which is a version management tool for nodejs. Both nvm and npm are node.js version management tools. In order to solve the incompatibility of various versions of node.js, you can use it to install and switch different versions of node.js
  2. You can click here to download the latest version on github . This download and installation is the windows version. Open the URL and we can see that there are two versions:

Three, nvm installation

  1. After uninstalling the previous node, install nvm, nvm-setup.exe installation version, and run nvm-setup.exe directly
    insert image description here
  2. Select the nvm installation path
    insert image description here
  3. Select the nodejs path
    insert image description here
  4. Just confirm the installation
    insert image description here
    5. Confirm after installation
    insert image description here

Open CMD, enter the command nvm, and the installation is successful, as shown below. You can see that there are various commands listed in it. The Chinese instructions of these commands are as follows:

  • nvm arch: Shows whether node is running on 32-bit or 64-bit.
  • nvm install <version> [arch]: Install node, version is a specific version or the latest stable version latest. The optional parameter arch specifies whether to install the 32-bit or 64-bit version, and the default is the system bit. --insecure can be added to bypass SSL for remote servers.
  • nvm list [available] : Show the list of installed ones. The optional parameter available displays all versions that can be installed. list can be simplified to ls.
  • nvm on : Enable node.js version management.
  • nvm off : Turn off node.js version management.
  • nvm proxy [url]: Set download proxy. Without the optional parameter url, the current proxy is displayed. Setting url to none removes the proxy.
  • nvm node_mirror [url] : Set node mirror. The default is https://nodejs.org/dist/. If no url is specified, the default url will be used. After setting, you can go to the settings.txt file in the installation directory to view it, or you can directly operate in this file.
  • nvm npm_mirror [url]: Set npm mirror. https://github.com/npm/cli/archive/. If no url is specified, the default url will be used. After setting, you can go to the settings.txt file in the installation directory to view it, or you can directly operate in this file.
  • nvm uninstall <version>: Uninstall the specified version node.
  • nvm use [version] [arch] : Use the specified version node. 32/64 bits can be specified.
  • nvm root [path]: Set the directory where different versions of node are stored. If not set, the current directory is used by default.
  • nvm version : Displays the nvm version. version can be simplified to v.
  1. nvm list availableDisplay a partial list of downloadable versions
    insert image description here
    nvm install latest Install the latest version (you can see the corresponding version numbers of node.js and npm during installation, it is not recommended to install the latest version)
    insert image description here
    nvm install version number Install the specified version of nodejs
    insert image description here

  2. View the installed version: nvm list or nvm ls to view the currently installed version (there is no * in front of the current version number, and no version is used at this time, and an error will be reported when using node.js)
    insert image description here

  3. Switch node version
    nvm use version number Use the specified version of nodejs (at this time, you will find that there is a * mark in front of the enabled node version, then you can use node.js) to
    insert image description here
    configure Taobao mirror source

    npm config set registry http://registry.npm.taobao.org/
    
    yarn config set registry http://registry.npm.taobao.org/
    
    npm get registry
    
    yarn config get registry
    

Fourth, configure the node environment

  1. First create two folders node_global and node_cache in the installation directory of node.js
    insert image description here
  2. 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 "E:\environment\nvm\nodejs\node_global"
npm config set cache "E:\environment\nvm\nodejs\node_cache" 
  1. Next, set the computer environment variables, right-click "My Computer" = "Properties = "Advanced System Settings = "Environment Variables to enter the following environment variable dialog box.
    insert image description here

5. Check whether the environment variables are consistent

  1. click computer

  2. right click click properties

  3. Select advanced system settings
    insert image description here

  4. Click on Environment Variables

  5. Check whether the environment variable is configured (automatically generated after the default nvm installation is successful): it is consistent
    with the following configuration:
    insert image description here
    if you have installed nodejs before, you need to change the environment variable of nodejs, if you do not delete the environment variable, nvm use is to switch unsuccessful
    insert image description here

Six, nvm common problems

  1. If the download of node is too slow, please replace the domestic mirror source. Under the installation path of nvm, find settings.txt, and set node_mirro and npm_mirror as the domestic mirror address. The download is fast~~
root: E:\environment\nvm\nvm
path: E:\environment\nodejs

//直接文件添加
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

//命令行
nvm npm_mirror https://npmmirror.com/mirrors/npm/
nvm node_mirror https://npmmirror.com/mirrors/node/

nvm list: List which versions of node are currently installed.
nvm uninstall [version]: Uninstall the specified version of node.
nvm node_mirror https://npm.taobao.org/mirrors/node/: Set the mirror of nvm.
nvm npm_mirror https://npm.taobao.org/mirrors/npm/: Set the mirror of npm.

  1. If after installing node in nvm, the following error occurs when using npm to install other plugins:

    npm ERR! Unexpected token ‘.’ npm ERR! A complete log of this run can
    be found in: npm ERR!
    E:\environment\nvm\nodejs\node_cache_logs\2023-08-21T08_15_00_020Z-debug-0.log

Then you can go to the nvm official website to download the latest version of nvm to solve the problem

Guess you like

Origin blog.csdn.net/qq_53810245/article/details/131926290