asdf安装不同版本的nodejs和yarn和pnpm

安装asdf

安装nodejs

nodejs版本

目前项目中常用的是14、16和18

安装插件

bash 复制代码
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
asdf plugin-add yarn https://github.com/twuni/asdf-yarn.git

可以查看获取所有的nodejs版本

bash 复制代码
asdf list all nodejs

有很多找到自己的想要的即可

可以查看大版本下的小版本

bash 复制代码
asdf list all nodejs 14
asdf list all nodejs 16
asdf list all nodejs 18

这里挑选的版本为:14.21.3.、16.20.218.19.0

bash 复制代码
asdf list all yarn
bash 复制代码
asdf install nodejs 14.21.3
asdf install nodejs 16.20.2
asdf install nodejs 18.19.0
# asdf install yarn 1.22.21
# asdf install yarn 1.22.10


刚刚上面的方式是默认全局安装,将之前的卸载,可以选择本地本安装

bash 复制代码
# 将nodejs 14.21.3设置为全局
asdf global nodejs 14.21.3
# 卸载nodejs 14.21.3版本
# asdf uninstall nodejs 14.21.3
# 重新安装 asdf install nodejs 14.21.3
asdf local nodejs 14.21.3



建议使用pnpm包管理器,可以用pnpm管理多个nodejs版本,下篇文章就研究pnpm管理多个nodejs

pnpm安装以及管理多个nodejs版本

失败记录

安装yarn

nodejs18以上才可以

bash 复制代码
asdf global nodejs 18.19.0

# nodejs<16.10,因为nodejs14太老了不支持,所以不安装其他包了
npm i -g corepack
# nodejs >=16.10
corepack enable
corepack prepare yarn@latest --activate # 这里需要指定版本,我制定了
asdf reshim nodejs 18.19.0

安装pnpm

nodejs18以上才可以

bash 复制代码
asdf global nodejs 18.19.0

# nodejs<16.10,因为nodejs14太老了不支持,所以不安装其他包了
npm i -g corepack
# nodejs >=16.10
corepack enable
corepack prepare pnpm@latest --activate
asdf reshim nodejs 18.19.0

应该是yarn安装的插件比较老,一直安装不上

下面的方式有问题不推荐,还是只能安装一个yarn,只有一个nodejs版本可以用
这样就可以针对单个项目使用了,开启对应的yarn

bash 复制代码
asdf install nodejs 16.20.2
cd node16
asdf local nodejs 16.20.2
asdf install nodejs 18.19.0
cd node18
asdf local nodejs 18.19.0
# nodejs<16.10,因为nodejs14太老了不支持,所以不安装其他包了
npm i -g corepack
# nodejs >=16.10
corepack enable
corepack prepare yarn@latest --activate # 需要写清楚yarn版本号,这里使用的是4.0.2
asdf reshim nodejs 16.20.2

asdf reshim nodejs 18.19.0

查看yarn版本https://github.com/yarnpkg/berry/releases



相关推荐
来一颗砂糖橘1 天前
pnpm:现代前端开发的高效包管理器
前端·pnpm
i建模1 天前
pnpm安装时过时警告的处理
pnpm
i建模1 天前
pnpm切换国内源
pnpm
Irene19914 天前
卸载依赖:pnpm 虚拟存储路径不一致
pnpm·卸载依赖
HuaCode6 天前
Openclaw一键安装部署(2026年4月最新)
git·python·nodejs·openclaw·api token
misty youth10 天前
pnpm build,发生了什么
前端·electron·pnpm·build
遇事不決洛必達12 天前
AST反混淆脚本
javascript·爬虫·nodejs·ast·ob混淆
老黑14 天前
开源工具 AIDA:给 AI 辅助开发加一个数据采集层,让 AI 从错误中自动学习(Glama 3A 认证)
前端·react.js·ai·nodejs·cursor·vibe coding·claude code
Ama_tor14 天前
Yarn |下载与配置+在 Excalidraw 项目中使用 Yarn
yarn·excalidraw
念念不忘 必有回响15 天前
Drizzle ORM上手指南:在Next.js中优雅地操作PostgreSQL
开发语言·postgresql·nodejs·nextjs·drizzle