Use nvm to switch node versions

When we develop vue codes in different scenarios, the node version used may cause conflicts, nvm is here

  1. delete uninstall existing node

  1. Download nvm (you can go to the official website)

Releases · coreybutler/nvm-windows (github.com)

Directly download one of these two

tip: If the download is slow or the download error is reported, click the third-party download below

Link: https://pan.baidu.com/s/1XYMxr3s7TMHyfzIYIGbSBw

Extraction code: sh2v

  1. After the download is complete, unzip and click Install until the next step . Be careful not to change the path

  1. After completion, open cmd and enter nvm - v to view the version, which proves that the installation is complete. If it cannot be recognized, you need to configure the environment variable

Modify according to the path where your nvm is located

  1. After the installation is complete, you need to configure nvm and switch the download source (if you can’t find this path, please show the hidden file)

Add the following two lines of code in setting.txt to switch the source

node_mirror: http://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
  1. Use nvm to install node and switch node

Commonly used nvm commands

nvm install stable ## 安装最新稳定版 node
nvm install <version> ## 安装指定版本
nvm uninstall <version> ## 删除已安装的指定版本
nvm use <version> ## 切换使用指定的版本node
nvm ls ## 列出所有安装的版本
nvm ls-remote ## 列出所有远程服务器的版本
nvm current ## 显示当前的版本
nvm alias <name> <version> ## 给不同的版本号添加别名
nvm unalias <name> ## 删除已定义的别名
nvm reinstall-packages <version> ## 在当前版本 node 环境下,重新   全局安装指定版本号的 npm 包
nvm alias default [node版本号] ##设置默认版本

For example: install the specified version node 14.17.1

nvm install 14.17.1 wait for the download to complete

View installed nvm ls

nvm use 14.17.1

View the current node version

View the current npm version

You can install other versions of node. For example, if I want to use the installed 19.6.1, I will use nvm use 19.6.1 to repeat the above operation

So far the nvm management node tool has been installed

last: switch npm installation dependency source during use

(1) Use the cnpm command line tool customized by Ali to replace the default npm

npm install -g cnpm --registry=http://registry.npmmirror.com

(2) Single use

npm install --registry=http://registry.npmmirror.com

(3) Permanent replacement

 npm config set registry http://registry.npmmirror.com

(4) Recovery

 npm config set registry https://registry.npmjs.org

(5) Check whether the installation is successful

npm config get registry
end

Guess you like

Origin blog.csdn.net/guoxingcheng1/article/details/129226649