preface

NVM can solve the problem of switching between multiple versions of Node. This article contains some common pitfalls and solutions, hoping to help you. NVM can be downloaded at github.com/coreybutler… If the download is too slow, I also provide version 1.1.7 at the end of this article for you to use.

The installation

After downloading the compressed package, double-click to run and accept the agreement, the following interface will appear:

Here you can set the installation location of NVM, in this case I set D:\ NVM, then click Next, the following screen will appear:

Here, you need to set the nodejs installation location. Note the following: The nodejs installation path must be within the NVM installation path, otherwise node will not be available later because we set the NVM installation location to D:\ NVM \nodejs. Then click Next and click Install to install.

Pay attention to

NVM_HOME and NVM_SYMLINK environment variables have been set properly after installation. You can enter the following command in CMD to confirm:

echo %NVM_HOME%
echo %NVM_SYMLINK%
Copy the code

If the file path is not present, you need to add these two variables to the environment variables, where NVM_HOME and NVM_SYMLINK correspond to the two locations set in the previous installation.

downloadnode

Before downloading, to improve the node download speed, we need to set the domestic image download address. We first need to find the location of the NVM folder and select settings.txt to modify it:

Then add the following configuration to the file:

node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
Copy the code

After saving, we can start to download node. First open CMD and type NVM install version to download the specified version. For example, in 8.9.1, we type NVM install 8.9.1. I also downloaded version 12.18.4, which I won’t show here:

We can then view the list of currently available Node versions using NVM ls:

Use NVM 8.9.1 to use this version, and then use node -v and NPM -v to confirm that node and NPM are working properly:

NVM use 8.9.1 node -v NPM -vCopy the code

Modify thenpmInstallation Package Location

Since the default download and installation location of NPM is on disk C, we may want to change the download location. We first type the following command on the command line:

npm config ls
Copy the code

You can then find the location of the configuration file:

Then we can find the location of.npMRc according to the path shown, and then open it with Notepad and change it to the location you want:

prefix=D:\nvm\nodejs\lib
cache=D:\nvm\nodejs\cache
Copy the code

conclusion

This article provides a brief introduction to the use and configuration of NVM. If you encounter some problems during the installation, you are welcome to share with us.

Download resources

Link: pan.baidu.com/s/1UnCzPJ5v… Extraction code: XUwn