认识
官网:https://asdf-vm.com/
文档:https://asdf-vm.com/guide/getting-started.html
仓库:https://github.com/asdf-vm/asdf
The Multiple Runtime Version Manager | Manage all your runtime versions with one tool!。简而言之,asdf,其为版本管理工具,能够管理多种运行时的不同版本,类似于 nvm venv 等等。
组成
确定版本的原理 .tool-versions
asdf performs a version lookup of a tool in all .tool-versions files from the current working directory up to the $HOME directory.
The lookup occurs just-in-time when you execute a tool that asdf manages.
环境的安装路径
ASDF_INSTALL_PATH ⇒ ~/.asdf/shims/
~/.asdf/installs
配置文件的路径
~/.asdfrc https://asdf-vm.com/manage/configuration.html#asdfrc
插件仓库 | Plugins Repository
https://github.com/asdf-vm/asdf-plugins
性质
所有命令 | https://asdf-vm.com/manage/commands.html
- 环境信息:asdf info
迁移现有版本管理工具配置
将其他版本配置文件(例如 .ruby-version/.nvmrc/.node-version 等等)迁移到 asdf 中。
插件多样化 | 自定义插件
内置插件 | https://github.com/asdf-vm/asdf-plugins/tree/master/plugins
创建插件 | https://asdf-vm.com/plugins/create.html
常用插件(部分插件虽非官方仓库内,但可能在内置插件列表中):
https://github.com/asdf-vm/asdf-nodejs
https://github.com/asdf-community/asdf-kubectl
https://github.com/halcyon/asdf-java
https://github.com/weibemoura/asdf-groovy
https://github.com/abinet/asdf-rancher.git
https://github.com/technikhil314/asdf-kompose.git
构建
v0.15.0 | 安装 | Ubuntu 24.04 LTS | Bash | Git |
# --------------------------------------------------------- # 安装 asdf 工具 apt install curl git git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.15.0 vim ~/.bashrc ... . "$HOME/.asdf/asdf.sh" ... . "$HOME/.asdf/completions/asdf.bash" # asdf scripts need to be sourced after you have set your $PATH # and after you have sourced your framework (oh-my-zsh etc). # --------------------------------------------------------- # 升级 asdf update
v0.18.0 | 升级 | Ubuntu 25.04
asdf versions 0.15.0 and older were written in Bash and distributed as a set of Bash scripts with the asdf function loaded into your shell. asdf version 0.16.0 is a complete rewrite of asdf in Go. Since it is a complete rewrite there are a number of breaking changes and it is now a binary rather than a set of scripts.
保留数据的升级过程:https://asdf-vm.com/guide/upgrading-to-v0-16.html#upgrading-without-losing-data
配置补全:
if which asdf > /dev/null then source <(asdf completion bash) fi
应用
—— 场景 | 方案
场景 | 安装 Node.js 环境
使用 asdf 工具,以安装 Node.js 为例
# --------------------------------------------------------- # 搜索插件 asdf plugin list all | grep nodejs # --------------------------------------------------------- # 添加插件 apt-get install dirmngr gpg curl gawk # 查看插件仓库,安装相关依赖 asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git asdf plugin add nodejs # 因其已存在 Plugin Repo 中,可直接添加 # --------------------------------------------------------- # 查看插件版本 asdf list all nodejs # 查看所有可用版本。注意,需要 asdf plugin add 之后,才能查看。 asdf list all nodejs 14 # 查看子版本 # --------------------------------------------------------- # 安装特定版本 asdf install nodejs latest # 安装最新版本 asdf current # 查看当前版本 # --------------------------------------------------------- # 使用特定版本 asdf set --home nodejs latest # ~/.tool-versions asdf set --parent nodejs latest # 向上遍历到根目录来找到 .tool-versions 文件 asdf set nodejs latest # ./.tool-versions
改进
… You have configured asdf to preserve downloaded files … But the current plugin … does not support that …
version v0.15.0
# vim .asdfrc
… always_keep_download = yes