NVM download and installation tutorial for NodeJS (environment variable configuration)

Foreword:A company has many projects, and the node version requirements of each project may be different. As a result, you have to re-download the node every time you switch projects, which is very troublesome. At this time, With nvm, it is very convenient and practical, and it is also a must-have for programmers.

1.What is nvm?

nvm, also called node.js version management in English, is a nodejs version management tool. nvm and n are both node.js version management tools. In order to solve the incompatibility of various node.js versions, you can use them to install and switch different versions of node.js.

Official website:nvm Documentation Manual - nvm is a nodejs version management tool - nvm Chinese website

2.nvm download and installation

2.1 Before installation, you must uninstall the node on your computer. Be sure to uninstall! nvm-setup.exe installation version, run nvm-setup.exe directly.

2.2 Select the nvm installation path and nodejs path. It is best not to put them in one file, but separate files.

2.3 After installation, nvm does not need to configure environment variables, it will be configured automatically.
2.4 Then configure the image source, open the NVM installation directory, find the settings.txt file, add two lines of content, save and exit.

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

3. Configure node_global and node_cache

3.1 First create two new folders node_global and node_cache in the NVM installation directory
3.2 After creating the two folders, enter the following commands in the cmd window (the two paths are the paths of the two folders)
npm config set prefix "C:\nvm\node_global"
npm config set cache "C:\nvm\node_cache"
3.3 Next set the computer environment variables, right-click "My Computer" => Properties => Advanced System Settings => Environment Variables, enter the following environment variables dialog box, click on the path of the user variable, create a new variable, and then click OK
3.4 Create a new variable NODE_PATH in the system variables, the value is C:\nvm\node_global\node_modules (file path)

3.5 After all settings are completed, click OK to complete the configuration.

4. Install node.js version

4.1nvm list available Shows a partial list of downloadable versions

4.2nvm install 10.24.1 Bring the version number to download
4.3 View the downloaded version

4.4 Switch node version
nvm use Version number uses the specified version of nodejs (at this time, you will find that there is a * mark in front of the enabled node version, then you can use node.js)

After 4.5, you can download which node version you want and switch to it at any time.

5. Because the npm server is abroad, sometimes downloading is very slow. At this time, we can use cnpm, but cnpm, if you don’t pay attention, cannot download at all, and this error message keeps appearing.

5.1 To solve why cnpm cannot be downloaded, execute the command first. When downloading, you must add the version number of cnpm.

Most of them are downloaded like this, and they cannot be downloaded at all:npm install -g cnpm --registry=https://registry.npm.taobao.org

Correct download method:

npm install [email protected] -g --registry=https://registry.npm.taobao.org
5.2 Check whether the download is successful

5.3 At this point, everything has been configured. Environment variables, node switching, and cnpm configuration are all set up. Whether it is a new computer or a new company, you can follow this step and it will be done.

Supongo que te gusta

Origin blog.csdn.net/shi15926lei/article/details/134962893
Recomendado
Clasificación