Foreword:
After learning nodejs, I installed nvm, npm, and nrm. When I first came into contact with it, I felt dizzy. After struggling all afternoon, I finally figured out these three big brothers. Let me take you through what these are, what they do, common commands and the errors I encountered. For me, it is also a review of the errors.
nvm
nvmis a version management tool for node.js. Using nvm to install node allows you to quickly switch node versions
Friends who have not installed nodejs can directly use nvm to install nodejs, which can reduce a lot of unnecessary trouble. It can also avoid a series of problems caused by installing the wrong version.
nvm download address: https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-setup.zip
Installation:
1. Open the .exe file and select the appropriate path for the first path.
2. The second path can be used by default.
3. If you have downloaded nodejs before installing nvm, a dialog box will pop up asking whether to use nvm to control the previously downloaded nodejs. Select yes.
4. After the installation is complete, open cmd and enter nvm version to view the version information. If the following prompt appears, the installation is successful.
Common commands
Command |
Description |
nvm list available |
Display all node.js versions that can be installed |
nvm list |
Show all installed node.js versions |
nvm use |
Switch to the specified nodejs version |
nvm install |
Install the specified version of node.js, for example: nvm install 8.12.0 |
nvm uninstall |
Uninstall the specified version of node.js, for example: nvm uninstall 8.12.0 |
nvm on |
Enable node.js version management |
nvm off |
Disable node.js version management (do not uninstall anything) |
Modify nvm download source
Find setting.txt
in the nvm directory and add the following code
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
npm
npm (node package manager) is a NodeJS package management and distribution tool, which has become the official standard for publishing Node modules (packages).
Installation: Installing nodejs comes with npm, you can view npm version information through npm -v
Note: It is recommended to use the npm version corresponding to the nodejs version, and generally there will be no errors.
Management: install installation/update package uninstall uninstall package publish publish
Example: npm install -g nrm (install nrm globally)
Configure global path:
In order to facilitate development and use, New npm_global and npm_cache folders are used for the global installation path and global cache path of npm packages respectively.
(Do not create these two folders in the nvm folder —> Otherwise, every time you use the npm installation package, an additional nvm folder will be generated in the project. You can use it with nvm Create a new folder in the same directory of the folder to store these two files)
1. Use the commands in the red part below to configure the global path. After configuring, check whether it is correct.
npm prefix -g |
View the global installation path of the current npm package |
npm config get cache |
View the global cache path of the current npm package |
npm config ls |
View configuration list |
npm config ls -l |
View all configuration list information |
npm config set prefix "E:\ |
Modify the global installation path of npm packages |
npm config set cache "E:\ |
Modify the global cache location of npm packages |
npm commands to view various global paths
[Note] Use nvm to switch node versions. It is recommended to check whether the npm global configuration path is correct
2. Configure environment variables
This computer->Properties->Advanced system settings->Environment variables->System variables->path->Edit->Add new path-E:\
(The path can be based on npm prefix – gCheck to ensure consistency)
odeJs\
pm_global
nrm
It is an npm source manager that can quickly switch npm image sources. Since the npm server is foreign, the default npm download speed is slow. You can use the domestic image source installation package by switching the image source.
Use the nrm ls command to view switchable image sources. * indicates the currently used image source.
In China, you can generally use the taobao mirror source, and change it according to personal needs.
View nrm version information command nrm -V
Supplement:
Package management tools also include: npm/cnpm/yarn/tyarn/pnpm. I won’t explain too much here. You can search for them separately.