Table of contents
What is asdf?
ASDF is a tool version manager. It allows developers to manage multiple versions of different programming languages, runtimes, and other development tools on a single system.
Fun fact: The name "asdf" comes from the first four letters on the left side of your keyboard. Try finding them!
Homepage: https://asdf-vm.com/
Key Features
- Single Configuration File: ASDF uses a
.tool-versions
file to specify the versions of all tools used in a project. - Version Control Friendly: The
.tool-versions
file can be committed to version control systems like Git, ensuring all team members use the same tool versions. - Plugin-based Architecture: ASDF can be extended to support various tools through plugins.
How It Works
- Shell Integration: ASDF integrates with your shell (like Bash or Zsh) to intercept commands.
- Plugins: Each tool (like Python, Node.js, etc.) is managed by a plugin.
- Shims: When you install a tool version, ASDF creates shims for its executables.
- Version Selection: When you run a command, ASDF checks the
.tool-versions
file and executes the specified version of the tool.
Advantages over Traditional Methods
- Consistency: Ensures all developers use the same tool versions, reducing "it works on my machine" issues.
- Simplicity: One tool to manage all version-specific dependencies, instead of using multiple version managers.
- Project-specific Configurations: Different projects can use different tool versions without conflicts.
- Automatic switching: You don't need to manually activate/deactivate environments as you switch between projects.
Example scenario
Let's say you have Python 3.8 and 3.9 installed via asdf, and your project's .tool-versions
specifies Python 3.9.5.
- You cd into your project directory.
- You type
python
in the terminal. - The asdf shim for Python is executed.
- Asdf reads the
.tool-versions
file. - It sees that Python 3.9.5 is specified for this project.
- Asdf then runs the Python 3.9.5 executable.
This process happens transparently and quickly, so it feels like you're just running Python normally.
Installing asdf on Ubuntu: A Step-by-Step Guide
Prepare Your System: First, ensure your system is up-to-date:
$ sudo apt update && sudo apt upgrade
Install required dependencies:
$ sudo apt install curl git
Install asdf:
$ cd ~ && git clone https://github.com/asdf-vm/asdf.git ~/.asdf
Add the following to ~/.bashrc or ~/.zshrc:
. "$HOME/.asdf/asdf.sh"
Restart your shell or source the configuration file
Verify installation:
$ asdf --version
Using asdf on Ubuntu: A Step-by-Step Guide
Add a plugin:
$ asdf plugin add []
# asdf plugin add nodejs
List All Available Versions:
$ asdf list all
# asdf list all nodejs
Install a version:
$ asdf install
# asdf install nodejs 18.0.0
List Installed Versions:
$ asdf list
# asdf list nodejs
Set a local version (in current directory):
$ asdf local
# asdf local nodejs 18.0.0
local writes the version to $PWD/.tool-versions, creating it if needed.