Requirements: The old project used by the company needs to use a lower version of node, but if I want to use the latest technology, I need to use a higher version of node, so I downloaded an nvm to manage multiple node versions and switch between them. Why do I still have to write so many nvm tutorials on the Internet, because the problems I encountered are too outrageous, I searched for all kinds of problems all morning, so I recorded them
1. Download nvm
GitHub official website address: nvm-window version address
Notice! ! ! Directly download the latest version 1.1.11. I followed others to install version 1.1.7 before. After downloading the higher version of node, I downloaded cnpm or other packages and reported an error directly. The error content is as follows. I have been looking for a long time because the nvm version is too low
Download the third one, you don’t need to unzip it, just install it directly
2. Install nvm
Notice! ! ! Do not appear Chinese in the installation path! ! ! It is best to create a folder called NVM yourself, and don't put it on the c drive
The third step is to create a folder called nodejs under the NVM folder to manage nodejs packages
Finally, keep clicking the next step until the end. You don’t need to change anything.
2.2 Configure Taobao Mirror
Find the nvm folder you installed, find the setting.txt file and open it
Add the following four sentences to set Taobao mirror
arch: 64
proxy: none
node_mirror: http://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
Finally save and close
3. Verify nvm installation and command
3.1 win+r to open the running window, enter cmd to open the terminal
3.2 View nvm version
nvm v
3.3 Don't rush to download, first open the system settings
Find Privacy and Security, then click Developer Options === "Open Developer Mode
3.4 nvm view all commands that can be used
nvm help
4. Install the node version
4.1 View the node version and the latest version recommended by nvm to download (only recommended, you can also download lower versions)
nvm list available
4.2 View the downloaded node version (I have downloaded two versions before, you can follow the one I downloaded)
nvm list
4.3 Download the node version. In order to demonstrate, here is my next 18 version (I still recommend downloading the 16 version haha)
nvm install 18.17.1
After downloading, there is a prompt, just follow the prompt to activate the version
5. Version switching and global download
Notice! ! ! Here I can download multiple different versions of node, just use the nvm install version number , but to switch versions, you need to use the nvm use version number to switch
5.1 Seeing that the node without the current system is already version 18
nvm use 18.17.1
Silky little combo switching version
node -v
nvm list
nvm use version
node -v
5.2 Download cnpm globally in version 18 (I haven’t downloaded version 16 at this time, let me show you the comparison)
Version 18 shows that the download was successful
npm install cnpm -g
5.3 Switch back to version 16 and see if there is cnpm
5.4 Uninstall unnecessary node versions
nvm install 版本号
5.5 Command summary
查看nvm版本
nvm v
查看nvm所有的命令
nvm help
查看nvm支持的node版本
nvm list available
查看下载的node版本和当前系统版本
nvm list
下载
nvm install 版本号
版本切换
nvm use 版本号
删除
nvm uninstall 版本号
6. After the installation and configuration, the terminal operation of VScode shows that the npm command cannot be found?
If you keep vscode open when you configure and install nvm, then you can close all vscode after you finish these, and then open the project to run it~
If there is still an error when running, remember to check whether the node version is the version required by your project. If not, just switch it, it's very convenient
The article ends here and I hope it will be helpful to you~