This article describes how to switch between node and NPM versions using NVM, and how to switch NPM download sources using NRM.
A, NVM
Nvm can be used to switch between node and NPM versions. When developing different projects, different versions of node and NPM may be used. Therefore, Nvm can be used to switch between different node and NPM versions.
Writing in the front
- Before installing the Nvm, uninstall the previously installed node. Otherwise, the node version cannot be changed
- Remove previously installed global plug-ins, otherwise the NVM command may not work. File directories are as follows
C:\Users\Administrator\AppData\Roaming\npm
C:\Users\Administrator\AppData\Roaming\npm-cache
Copy the code
The installation of NVM
Download the NVM plug-in at Github: Download NVM – Windows (NVM -setup.zip).
After the download is complete, decompress the file and double-click to install:
-
- Set up the
nvm
Installation directory, the path here can be filled in according to their own needs, do not include Chinese name
- Set up the
-
- Set up the
nodejs
Installation directory of each version. This directory isNVM install Node version
When storingnodejs
The directory where the
- Set up the
-
- When the installation is complete, type:
nvm version
If the version number is displayed, the NVM is successfully installed.
- When the installation is complete, type:
NVM common commands
nvm install latest
: Install the latestnodejs
versionNVM install 11.12.0
: Installs the correspondingnodejs
versionNVM uninstall 11.12.0
: corresponds to uninstallationnodejs
versionnvm list available
: Lists all availablenodejs
versionnvm list
: seenvm
List what has been installednodejs
versionNVM use 11.12.0
: Use the correspondingnodejs
version- Enter more commands on the command line
nvm
To view
Q&A
-
Note that NVM is not an internal or external command problem
- Delete the global package installed by NPM. The file directory is as follows:
C:\Users\Administrator\AppData\Roaming\npm C:\Users\Administrator\AppData\Roaming\npm-cache Copy the code
-
The NVM switchover node version is invalid
- Uninstall the original node version and the global installation package
-
NVM download speed is slow
- Find it in the NVM installation directory
settings.txt
File, add the following two lines of code:
root: D:\DevTools\NVM\nvm path: D:\DevTools\NVM\nodejs + node_mirror: https://npm.taobao.org/mirrors/node/ + npm_mirror: https://npm.taobao.org/mirrors/npm/ Copy the code
- Find it in the NVM installation directory
Second, the NRM
In the process of using NPM, the plug-in installation may be slow, so we may use Taobao source to download and install the plug-in. Or within the company, there are some private plug-ins that can be downloaded using the company’s source. In this case, we need to set up a different source for the download. Setting it manually each time is relatively cumbersome. And NRM can solve this problem very well.
The installation of NRM
Install NRM globally
$ npm install nrm -g
Copy the code
When the installation is complete, enter the command NRM ls and you can see that there are already 6 sources by default (the one with an asterisk is the one currently in use).
* npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
npmMirror https://skimdb.npmjs.com/registry/
edunpm - http://registry.enpmjs.org/
Copy the code
Enter NRM Use Taobao, that is, switch Registry to Taobao, and you can use the source of Taobao to install and download the plug-in.
NRM Common commands
nrm ls
: View all configured sources and their namesnrm add company http://npm.xxx.cn
: Add source,company
Is the name, you can name it yourself, followed by the sourceurl
addressnrm del company
: Delete the source by namecompany
You can delete the corresponding sourcenrm test [registry]
: Tests the speed of the source without adding the correspondingregistry
Name, test the speed of all sources, add the corresponding name, such ascompany
That is testingcompany
The velocity of the corresponding sourcenrm use company
: Switches the source and can be usedcompany
The source of the corresponding name- Enter more commands on the command line
nrm
To view
Three, additional knowledge points
-
Install CNPM: NPM install – g CNPM – registry=https://registry.npm.taobao.org
-
Set the installation path of the NPM global package (don’t do this if you don’t want to control the installation path yourself) :
- Execute command:
npm config set prefix "D:\DevTools\Nvm\npm-global"
- Set environment variables: Set Path to:
C:\\Users\\Administrator\\AppData\\Roaming\\npm
Modified toD:\\DevTools\\Nvm\\npm-global
- Execute command:
-
To view the installed global package, run the NPM ls -g –depth=0 command
-
Set the NPM source manually
npm config get registry
: View the current NPM sourcenpm config set registry https://registry.npm.taobao.org/
: Set NPM source as Taobaonpm install --registry=https://registry.npm.taobao.org
: Installs all dependent packages using a specific sourcenpm install express --registry=https://registry.npm.taobao.org
: Installs the Express package using a specific source
4. Reference links
- Install the NVM management NodeJS version on Windows
- NPM Source Manager NRM tutorial