[Web前端]node多版本控制器nvm

文章目录

nvm下载安装

https://github.com/coreybutler/nvm-windows/releases

不方便的可使用百度云下载

链接:https://pan.baidu.com/s/1gDUMpbYdz24dHmedPEKRdg

提取码:anan

查看目前可用版本

bash 复制代码
// 查看目前可用node版本
nvm list available

得到如下结果

bash 复制代码
C:\Users\fir>nvm list available

|   CURRENT    |     LTS      |  OLD STABLE  | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
|    21.6.1    |   20.11.0    |   0.12.18    |   0.11.16    |
|    21.6.0    |   20.10.0    |   0.12.17    |   0.11.15    |
|    21.5.0    |    20.9.0    |   0.12.16    |   0.11.14    |
|    21.4.0    |   18.19.0    |   0.12.15    |   0.11.13    |
|    21.3.0    |   18.18.2    |   0.12.14    |   0.11.12    |
|    21.2.0    |   18.18.1    |   0.12.13    |   0.11.11    |
|    21.1.0    |   18.18.0    |   0.12.12    |   0.11.10    |
|    21.0.0    |   18.17.1    |   0.12.11    |    0.11.9    |
|    20.8.1    |   18.17.0    |   0.12.10    |    0.11.8    |
|    20.8.0    |   18.16.1    |    0.12.9    |    0.11.7    |
|    20.7.0    |   18.16.0    |    0.12.8    |    0.11.6    |
|    20.6.1    |   18.15.0    |    0.12.7    |    0.11.5    |
|    20.6.0    |   18.14.2    |    0.12.6    |    0.11.4    |
|    20.5.1    |   18.14.1    |    0.12.5    |    0.11.3    |
|    20.5.0    |   18.14.0    |    0.12.4    |    0.11.2    |
|    20.4.0    |   18.13.0    |    0.12.3    |    0.11.1    |
|    20.3.1    |   18.12.1    |    0.12.2    |    0.11.0    |
|    20.3.0    |   18.12.0    |    0.12.1    |    0.9.12    |
|    20.2.0    |   16.20.2    |    0.12.0    |    0.9.11    |
|    20.1.0    |   16.20.1    |   0.10.48    |    0.9.10    |

This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases

安装完之后查看版本

bash 复制代码
// 安装指定版本的node
nvm install 20.11.0
// 查看当前已安装的node
nvm ls
// 使用指定版本的node
nvm use xxx

得到如下结果

bash 复制代码
C:\Users\fir>nvm install 20.11.0
Downloading node.js version 20.11.0 (64-bit)...
Extracting node and npm...
Complete
npm v10.2.4 installed successfully.


Installation complete. If you want to use this version, type

nvm use 20.11.0

C:\Users\fir>nvm ls

    20.11.0
    
C:\Users\fir>nvm use 20.11.0
Now using node v20.11.0 (64-bit)

C:\Users\fir>nvm ls

  * 20.11.0 (Currently using 64-bit executable)

查看镜像源与npm所有配置

bash 复制代码
// 查看当前当前版本镜像源
npm get registry
// 查看当放前所有配置
npm config ls

得到如下结果

bash 复制代码
C:\Users\fir>npm get registry
https://registry.npmjs.org/

C:\Users\fir>npm config ls
; node bin location = D:\Application\work\nodejs\node.exe
; node version = v20.11.0
; npm local prefix = C:\Users\fir
; npm version = 10.2.4
; cwd = C:\Users\fir
; HOME = C:\Users\fir
; Run `npm config ls -l` to show all defaults.

修改镜像源与npm配置

创建node_cache与node_global文件夹(本文安装在nvm同级目录下)

bash 复制代码
node_cache
node_global
bash 复制代码
C:\Users\fir>npm get registry
http://registry.npm.taobao.org/

C:\Users\fir>npm config ls
; "user" config from C:\Users\fir\.npmrc

cache = "D:\\Application\\work\\nvm\\node_cache"
prefix = "D:\\Application\\work\\nvm\\node_global"
registry = "http://registry.npm.taobao.org"

; node bin location = D:\Application\work\nodejs\node.exe
; node version = v20.11.0
; npm local prefix = C:\Users\fir
; npm version = 10.2.4
; cwd = C:\Users\fir
; HOME = C:\Users\fir
; Run `npm config ls -l` to show all defaults.

安装其他版本

bash 复制代码
C:\Users\fir>nvm install 18.19.0
Downloading node.js version 18.19.0 (64-bit)...
Extracting node and npm...
Complete
npm v10.2.3 installed successfully.


Installation complete. If you want to use this version, type

nvm use 18.19.0
C:\Users\fir>nvm ls

  * 20.11.0 (Currently using 64-bit executable)
    18.19.0
    
C:\Users\fir>nvm use 18.19.0
Now using node v18.19.0 (64-bit)
C:\Users\fir>nvm ls

    20.11.0
  * 18.19.0 (Currently using 64-bit executable)

此时再查看npm配置,可知,即使切换版本,配置依然生效

bash 复制代码
C:\Users\fir>npm get registry
http://registry.npm.taobao.org/

C:\Users\fir>npm config ls
; "user" config from C:\Users\fir\.npmrc

cache = "D:\\Application\\work\\nvm\\node_cache"
prefix = "D:\\Application\\work\\nvm\\node_global"
registry = "http://registry.npm.taobao.org"

; node bin location = D:\Application\work\nodejs\node.exe
; node version = v18.19.0
; npm local prefix = C:\Users\fir
; npm version = 10.2.3
; cwd = C:\Users\fir
; HOME = C:\Users\fir
; Run `npm config ls -l` to show all defaults.

安装结束

node文件都将在nvm同级目录下

相关推荐
MK-mm8 分钟前
CSS盒子 flex弹性布局
前端·css·html
小小小小宇21 分钟前
CSP的使用
前端
sunbyte22 分钟前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | AnimatedNavigation(动态导航)
前端·javascript·vue.js·tailwindcss
ifanatic31 分钟前
[每周一更]-(第147期):使用 Go 语言实现 JSON Web Token (JWT)
前端·golang·json
烛阴32 分钟前
深入浅出地理解Python元类【从入门到精通】
前端·python
米粒宝的爸爸35 分钟前
uniapp中vue3 ,uview-plus使用!
前端·vue.js·uni-app
JustHappy1 小时前
啥是Hooks?为啥要用Hooks?Hooks该怎么用?像是Vue中的什么?React Hooks的使用姿势(下)
前端·javascript·react.js
董先生_ad986ad1 小时前
C# 解析 URL URI 中的参数
前端·c#
江城开朗的豌豆1 小时前
Vue中Token存储那点事儿:从localStorage到内存的避坑指南
前端·javascript·vue.js
江城开朗的豌豆1 小时前
MVVM框架:让前端开发像搭积木一样简单!
前端·javascript·vue.js