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



相关推荐
懒羊羊我小弟16 小时前
常用 Webpack Plugin 汇总
前端·webpack·npm·node.js·yarn
一雨方知深秋3 天前
pnpm, eslint, vue-router4, element-plus, pinia
pnpm·pinia·element-plus·暂存区eslint·vue-router4
太阳与星辰9 天前
pnpm的使用
pnpm·包管理工具
belldeep21 天前
nodejs:express + js-mdict 网页查询英汉词典
nodejs·express·js-mdict
荣--22 天前
回顾我的软件开发经历:开发DAB
c++·单元测试·项目管理·nodejs·dab·多平台支持·正交性原则
belldeep23 天前
nodejs:js-mdict 的下载、安装、测试、build
nodejs·jest·yarn·nvm
Lilixxs25 天前
开发环境搭建-3:配置 JavaScript 开发环境 (fnm+ nodejs + pnpm + nrm)
linux·运维·javascript·pnpm·fnm
顧棟1 个月前
【ES实战】治理项之索引模板相关治理
大数据·elasticsearch·yarn
小新1101 个月前
微信小程序获取openid
微信小程序·小程序·nodejs
坐忘3GQ1 个月前
119.使用AI Agent解决问题:Jenkins build Pipeline时,提示npm ERR! errno FETCH_ERROR
运维·npm·jenkins·nodejs·jenkinsfile·文心快码·fetch_error