Node | Use nvm to solve multi-version node switching problems

Preface

I believe that many people will need to use different nodeversions for multiple projects . If you uninstall and install each time, nodeit will be very troublesome to manage the version by yourself . By using nvmit, we can solve nodethe problem of switching between multiple versions . This article contains common Pit and solution, I hope to help you, nvmthe other download address is https://github.com/coreybutler/nvm-windows/releases , if the download is too slow, I also provide the 1.1.7 version at the end of the article milk.

installation

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

image-20200916155049507

Here you can set nvmthe installation location, here I set it D:\nvm, and then click next, the following interface will appear:

image-20200916155227618

What needs to be set here is nodejsthe installation location, here we need to pay special attention: nodejsthe installation path must be within nvmthe installation path , otherwise it will not be available later node, because we set nvmthe installation location to D:\nvm, here we set nodejsthe installation location Set the order D:\nvm\nodejs, and then click nextand then click installto install.

note

After installation, we need to confirm nvmthe environment variables NVM_HOMEand NVM_SYMLINKwhether they are properly set up. You can cmdenter the following command to confirm:

echo %NVM_HOME%
echo %NVM_SYMLINK%

If you get the results normally (the folder path is printed), you can ignore the next step. If the file path does not appear, you need to add these two variables to the environment variables, NVM_HOMEand the sum NVM_SYMLINKcorresponds to the setting in the installation above Two positions.

downloadnode

Before downloading, in order to improve nodethe download speed, we need to set the domestic mirror download address first. We first need to find nvmthe location of the folder, and then choose settings.txtto modify it:

image-20200916161502053

Then add the following configuration to the file:

node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

image-20200916161616826

After saving, we can start nodethe download, first open it cmd, and then enter it nvm install versionto download the specified version, here is 8.9.1 as an example, we enter nvm install 8.9.1, after a while, the following content will appear, I also downloaded 12.18 The .4 version is not shown here:

image-20200916161955900

Then we nvm lscan view the nodelist of currently available versions through:

image-20200916162116958

Then we nvm use 8.9.1can use the version by passing, and then passing node -vand npm -vconfirming nodeand npmall can be used normally:

nvm use 8.9.1
node -v
npm -v

image-20200916162257228

Modify the npminstallation package location

Since the npmdefault download and installation location is on the C drive, we may want to modify the download location. We first enter the following command in the command line:

npm config ls

Then you can find the location of the configuration file:

image-20200916162713689

Then we find .npmrcthe location according to the displayed path , then open it with Notepad and modify it to the location we want to store:

prefix=D:\nvm\nodejs\lib
cache=D:\nvm\nodejs\cache

image-20200916162902856

to sum up

This article briefly introduces the nvmusage and configuration methods. If you encounter some problems during the installation, you are welcome to communicate.

Download

Link: https://pan.baidu.com/s/1UnCzPJ5v_oo-JhA-nK4_uw
Extraction code: xuwn

Guess you like

Origin blog.csdn.net/qq_41698074/article/details/108625218