NVM is the Node version manager, a simple bash script that manages multiple active Node.js versions, allowing us to set the default Node version and switch between different versions in different development environments.

Install the NVM

  1. Open the download address and download the installation package.

  1. Double-click the installation file nVM-setup.exe, agree to the protocol and click Next

  1. Select the NVM installation path

  1. Select the nodeJS path

  1. Click the Install button to install

  1. After installation open the console and enternvmIf the installation is successful, the following information is displayed:

The NVM takes too long to install Node and NPM

The default node image source of the NVM is https://nodejs.org/dist. Downloading from the default image source is slow. Therefore, you can change the image source to speed up the downloading

  1. Locate the folder where you installed NVM and open itsettings.txtfile

  1. Two lines of configuration are added and replacednodeandnpmDownload source for Taobao mirror source
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
Copy the code

Install Node.js using NVM

  1. The input terminalnvm lsView the installednode.jsVersion.*Selected is the version currently in use.
nvm ls
Copy the code

  1. usenvmInstall the specified versionnode.js
NVM install 14.17.6Copy the code

As shown in the following figure, the installation of the specified version of Node.js and NPM is successful

Added a folder for the specified version to the NVM folder directory

The folder contains installed packages for Node, NPM, and NPX

  1. Use the specified versionnode.jsTo see thenodeandnpmVersion.
NVM use 14.17.6Copy the code

  1. Uninstall the specified versionnode.js
NVM uninstall 14.17.6Copy the code

Command Prompt description

  • nvm arch [32|64]: Shows whether node runs on 32-bit or 64-bit.
  • nvm current: Displays the active version.
  • nvm install <version> [arch]: Installs Node. Version can be a specific version or latest stable version. The optional arch parameter specifies whether to install the 32-bit or 64-bit version, which defaults to system bits. You can add –insecure to bypass SSL for the remote server.
  • nvm list [available]: Displays the installed list. The optional parameter available displays all versions that can be installed. List can be simplified to ls.
  • nvm on: Enables node.js version management.
  • nvm off: Disables node.js version management.
  • nvm proxy [url]: Sets the download agent. Displays the current proxy without the optional URL. Setting the URL to None removes the proxy.
  • nvm uninstall <version>: Uninstalls the specified version of Node.
  • nvm use [version] [arch]: Use the specified version of Node. 32/64 bits can be specified.
  • nvm root [path]: Sets the directory to store different versions of Node. If no, the current directory is used by default.
  • nvm version: Displays the NVM version. Version can be simplified to v.
  • nvm node_mirror [node_mirror_url]: Sets the node mirroring. The default ishttps://nodejs.org/dist/. If the URL is not written, the default URL is used. You can view the Settings in installation directory settings. TXT or perform operations in this file.
  • nvm npm_mirror [npm_mirror_url]: Sets the NPM mirror. The default ishttps://github.com/npm/cli/archive/. If the URL is not written, the default URL is used. You can view the Settings in installation directory settings. TXT or perform operations in this file.

Installation of yarn

  1. Use what’s already installednpmTo install theyarn
npm install yarn -g
Copy the code
  1. To viewyarnversion
yarn -v
Copy the code

  1. usenvmforThe node versionManage after eachThe node versionAll the following need to be installedyarnAfter the installation, the specified version folder will be addedyarnfile

Set the Taobao mirroring for NPM and YARN

Taobao NPM image is a complete nPMjs.org image, you can use this instead of the official version (read only) to greatly improve the download speed of the package, the synchronization frequency is currently 10 minutes to ensure as much as possible with the official service synchronization.

  1. Set up thenpmTaobao mirror
npm config set registry http://registry.npm.taobao.org/
Copy the code
  1. Set up theyarnTaobao mirror
yarn config set registry http://registry.npm.taobao.org/
Copy the code
  1. Example Query the current mirror
npm get registry
yarn config get registry
Copy the code