node version management tool nvm

Get into the habit of writing together! This is the 9th day of my participation in the "Nuggets Daily New Plan · April Update Challenge", click to view the details of the event .

We all know that many popular frameworks on the Internet basically follow 前后端the route of separation, which means that most programmers have to accept front-end technologies, such as: vue, reactetc. front-end frameworks ! ! ! ^_^

As we develop more projects, different projects use different frameworks, and there are also 本地开发环境equivalent restrictions, such as nodeversion restrictions, this is a comparison 头疼problem.

E.g:

  • Project A, needs to be in v10.5.0
  • Project B, needs to be in v12.16.1

That's disgusting for developers! ! ! =_=

image.png

If I want to run project A, I have to switch to node 10.5.0version; to run project B, I have to switch to node 12.16.1version. This 切换工作, you have to 重新install node! ! ! =_=

If you do this every time, you shouldn't be a waste of time! ! ! =_=

As one 牛皮的程序员, why can't we do this! ! !

According to what you said 切换, how can this be done in a comparatively 快捷way?image.png

Not much nonsense, there must be, it is the protagonist nvmtool we are going to share today.

nvmThe tool is a nodeversion management tool that can help us quickly switch the local development environment node的版本.

image.png

nvm install

1. Download nvm

1. Download address

From githubabove, download the latest version: download address

Here, how do we choosenvm-setup.zip

image.png

注:本文下载版本:1.1.9(目前最新,目前时间2022-04-09)

2.安装nvm

解压安装:nvm-setup.zip,一步步安装即可,不需要改什么东西!!!(这很关键)

打开cmd,输入nvm命令,看到以下信息,表示已经安装成功了

image.png

注意:安装的时候,建议用默认的安装路径即可,不建议修改安装路径,否则会导致某些问题。不按照建议做的,后果自己承担哈!!!

image.png

二、配置加速镜像

因为nvm默认的下载地址,使用的是一个外国的地址,速度比较慢呀,这个是不能忍的啦!!!

咋们这里切换到淘宝的镜像,下载速度快到你不可信喔!!!^_^

image.png

配置方法:

打开nvm的安装路径,默认安装路径是:C:\Users\Administrator\AppData\Roaming\nvm

image.png

对settings.txt,进行修改,后面加上淘宝的nodenpm镜像地址即可

root: C:\Users\Administrator\AppData\Roaming\nvm
path: C:\Program Files\nodejs


node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
复制代码

三、安装node

1.nvm安装命令:

nvm install v10.5.0
复制代码

image.png

这里是因为npm无法下载,导致安装失败了。可能是github的地址不太稳定导致。

好家伙,npm安装失败了,这可咋整?别急,这里哥们还是有办法解决,接着往下!!!

image.png

这里分析一下,nvm下载的node,就会放到这个路径下面,那咋们岂不是可以自己下载node,然后放入到这个路径下,nvm就可以进行管理node的版本呢?好像就是这样...

那么这样的话,我们手动下载node,放入到这个路径下,不就好了?

手动下载nodejs10.5.0 image.png

image.png

因为node10.5.0通过nvm安装失败了,我们得清一下这个有问题的node

卸载命令:

nvm uninstall 10.5.0
复制代码

image.png

同时把temp也删了

image.png

Then, unzip it directly node-v10.5.0-win-x64.zipand change the folder name tov10.5.0

image.png

Finally look at the effect:

nvm list    //列出所有node版本
复制代码

image.png

Good guy, this way nvmyou can manage this too node10.5.0, Niu Niu Niu! ! ! ^_^

image.png

Switch to use the specified version of node

nvm use 10.5.0
复制代码

image.png

image.png

nodejsA star here indicates the version currently in use

In the same way, let's proceed to install: 12.16.1and16.14.0

image.png

The download address of the historical version of nodejs

image.png

switch to16.14.0

image.png

View node, npmversion, normal use

image.png

See, switching is so easy, 丝滑ah! ! ! Perfect! ! ! ^_^

image.png

To summarize the nvm command:

Order effect
nvm list List all node versions
nvm use 10.5.0 Switch the specified version of node
nvm install v10.5.0 Install the specified node version
nvm uninstall v10.5.0 Uninstall the specified node version

Well, that's all for the basic installation and operation of nvm, and we can write code happily! ! ! ^_^

image.png

Guess you like

Origin juejin.im/post/7084439598406828063