Skip to content

asdf

asdf 是一个可以同时管理多个语言、运行时的版本管理工具

下载安装

zsh
# 1. 下载安装前提依赖项
% brew install coreutils curl git

# 2. 下载安装 asdf
% brew install asdf

# 3. 追加环境变量到 ~/.zshrc 文件
% echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

目录结构

asdf 通过一个版本管理文件.tool-versions控制当前工作区目录下的各个语言与运行时的版本

该文件在执行命令版本切换版本时会自动更新

[全局目录]

├─ [工作区目录]/
│   ├─ .tool-versions
│   └─ ...

├─ [工作区目录]/
│   ├─ [项目目录]/
│   │   ├─ .tool-versions
│   │   └─ ...
│   ├─ [项目目录]/
│   │   ├─ .tool-versions
│   │   └─ ...
│   ├─ .tool-versions
│   └─ ...

├─ .tool-versions
└─ ...

常用命令

下载语言/运行时

zsh
# 1. 安装语言/运行时的插件
% asdf plugin add [插件]

# 2. 安装语言/运行时的具体版本
% asdf install [语言/运行时] [版本]

下载前建议先查看所有可以安装的版本

zsh
% asdf list all [语言/运行时]
例子:下载 Node.js、Python、Golang
zsh
% asdf plugin add nodejs
% asdf plugin add python
% asdf plugin add golang

% asdf install nodejs 18.18.0
% asdf install python 3.10.0
% asdf install golang 1.18

卸载语言/运行时

zsh
% asdf uninstall [语言/运行时] [版本]

设置版本

zsh
% asdf global [语言/运行时] [版本]
% asdf reshim [语言/运行时]
zsh
% cd [工作区目录]
% asdf local [语言/运行时] [版本]
% asdf reshim [语言/运行时]

asdf reshim

设置版本后需要执行该命令来更新 shim 文件,确保其指向新的版本,否则系统可能仍然使用旧版本


查看版本

zsh
% asdf list
语言/运行时
  版本
 *版本
  版本
语言/运行时
  版本
  版本
 *版本
zsh
% cd [工作区目录]                 
% asdf current
语言/运行时       版本             /Users/用户/路径/.tool-versions
语言/运行时       版本             /Users/用户/路径/.tool-versions
语言/运行时       版本             /Users/用户/路径/.tool-versions

最近更新: