Win10 environment uses nvm to install multi-version nodejs and configure environment variables

Win10 environment uses nvm to install multi-version nodejs and configure environment variables


Recently, using the node project requires multiple versions and switching. It is troublesome to install and uninstall different versions of node back and forth. Later, I will simply use nvm to manage node, and record my own use process by the way, so as to facilitate subsequent search.

nvm install


1.nvm installation, first download https://github.com/coreybutler/nvm-windows/releases from the official website
insert image description here
and then install nvm-setup.exe:
insert image description here
insert image description here
Note: The above two addresses, the default is the C drive, now change to D plate. Also, remember that there should be no spaces in the folder name of the installation path, otherwise the symbol format will be incorrect when NPM is used later.
There are two ways to configure the installation directory of nvm and switch to Taobao:
(1) Use the command:

//命令行中输入一下命令进行配置
nvm node_mirror https://npmmirror.com/mirrors/node/
nvm npm_mirror https://npmmirror.com/mirrors/npm/

(2) Manually change directly:

insert image description here
Manually add
node_mirror: https://npm.taobao.org/mirrors/node/ npm_mirror: https://npm.taobao.org/mirrors/npm/
these two sentences to setting.txt
, save and exit.insert image description here

After the installation is complete, start to insert nodejs, first use '' nvm list availableto query the insertable version number, LST means insertable stable version,
insert image description here
then use the NVM command to directly insert the corresponding version of nodejs:
nvm install 16.18.1
After the insertion is completed:
insert image description here
The inside of the v16.18.1 file is:
insert image description here
if the following During use, if there is a problem with npm, check whether npm is installed normally from V16.18.1.
The inside of node_modules is like this,
insert image description here
nvm switches node, uninstalls node, and replaces the current computer with node version

nvm install 16.18.1   // 安装node4.6.2版本(附带安装npm)
nvm uninstall 16.18.1 // 卸载node4.6.2版本
nvm list            // 查看已安装node版本
nvm use 16.18.1       // 将node版本切换到4.6.2版本

Environment variable configuration

Start configuring environment variables:

First create two folders "node_global" and "node_cache". When performing global installation, install the corresponding library to these two files. Create two new folders in the node installation path of nvm D:\NVMinstall\nodejs, named "node_global" and "node_cache".
insert image description here
Set computer environment variables, right-click "My Computer" - Properties - Advanced System Settings - Environment Variables to enter the following dialog box of environment variables.
1) Create a new environment variable NODE_PATH in [System Variables], the value is D:\install\nodejs\node_global\node_modules, where D:\install\nodejs\node_global is the global module installation path folder created above
insert image description here

2) Modify the path variable in [User Variables], and change C:\Users\hua\AppData\Roaming\npm to D:\install\nodejs\node_global. The final result is this: after creation, enter in the
insert image description here
cmd
insert image description here
window The following commands (the two paths are the paths of the two folders), the main purpose is to facilitate the use of later window machines:
npm config set prefix “D:\NVMinstall\nodejs\node_global”
npm config set cache “D:\NVMinstall \nodejs\node_cache”
3) After clicking OK, the configuration is complete.

Test install global modules

1). To test whether the configuration is successful, enter the following in the cmd window to specify the global installation of the express module
npm install -g express
insert image description here

If the network speed is relatively poor, you can also switch the mirror source that currently uses the node version npm:

npm config set registry=https://registry.npm.taobao.org/

For older versions of node, manually install npm

If you fail to insert when you insert nvm: you can download the corresponding npm version to decompress the package, and then replace it with the corresponding npm inside. Take this 8.11.1 as an example. After the installation is complete, there is actually no npm of.
Then find https://nodejs.org/en/download/releases/ to view the corresponding version, or you can directly view the version information in the error.
insert image description hereAt this time, the v8.11.1 and node_modules files are actually empty: insert image description hereinsert image description here
so our version 8.11.1 When node is running, there is no npm to use.
(1) First download the npm decompression package
insert image description here
(2) Create a new npm folder, the path is D:\NVMinstall\nvm\v8.11.1\node_modules\npm
insert image description here
Copy several files in the bin in the decompression package to V8.11.1, the operation is as follows:
insert image description here
insert image description here
insert image description here
(3) Put all the other files decompressed Go to the newly created npm, as shown in the figure:
insert image description here
Finally, verify whether the node 8.11.1 version we installed can be used normally:
insert image description here
In this case, different versions of nodejs can be used normally in other compilation environments of vs code and windows.

Guess you like

Origin blog.csdn.net/weixin_40625478/article/details/128715734