- Published on
asdf: A Powerful Version Manager for macOS
- Authors
- Name
Explore asdf, a versatile version manager for macOS that simplifies managing tools and runtimes like Python, Golang, and Terraform in a streamlined workflow. Supplemental notes to my MacDevOps:YVR Conference 2022 session.
asdf is a powerful and flexible version manager for macOS and Linux, designed to streamline the management of multiple programming languages and development tools. With a single CLI interface, you can install, manage, and effortlessly switch between versions of Python, Golang, Terraform, and more. Whether you’re juggling various project requirements or keeping your tools up to date, asdf makes it simple and efficient.
This guide offers a first overview of asdf, focusing on its initial setup and usage on macOS. It also serves as a supplementary resource to my MacDevOps:YVR 2022 conference talk: Runtime and Tools Version Management on macOS. Slides for the talk are available here.
What Makes asdf Stand Out?
- Unified Management: Use one tool to manage versions of diverse runtimes and programming languages.
.tool-versionsFile: Simplify version control across projects using a single configuration file.- Plugin-Based Architecture: Add support for a wide range of tools and languages.
- Local Overrides: Easily define tool versions for specific projects.
- Less Dependence on Package Managers: Avoid conflicts from package manager installations like Homebrew.
Setting Up asdf on macOS
1. Install Prerequisites
- Install Xcode Command Line Tools:bash
xcode-select --install - Install Core Utilities (choose one method):
- Homebrew:bash
brew install coreutils - GPGTools: Download GPGTools for Mac and custom install MacGPG to
/usr/local/MacGPG2.
2. Install asdf
Clone the asdf repository to your home directory and set it up:
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.33. Configure Shell Integration
Add the following to your shell configuration file (e.g., ~/.zshrc for zsh):
# Add to your ~/.zshrc
. $HOME/.asdf/asdf.sh
# Append completions to fpath
fpath=(${ASDF_DIR}/completions $fpath)
# Initialize completions with ZSH's compinit
autoload -Uz compinit && compinitFor detailed shell-specific instructions, refer to asdf's documentation.
Getting Started with asdf
Key Facts
- Shell Script:
asdfis implemented as a shell script. - Git-Based Plugins: Plugins fetch available versions and handle installations via Git.
- Hidden Directory: Everything is stored in
~/.asdf, including installations under~/.asdf/installs. - Configuration File: The
.tool-versionsfile specifies tool versions for directories and projects.
Core Commands
- Set global version:bash
asdf global <name> <version> - Set local version for a project:bash
asdf local <name> <version> - Install latest version:bash
asdf install <name> latest - List installed versions:bash
asdf list <name> - List available versions:bash
asdf list all <name>
Quick Installation Guide for Popular Tools
Python
Install the latest Python version:
asdf plugin add python
asdf install python latest
asdf global python latestAdd default Python packages:
# Create $HOME/.default-python-packages
ansible
pipenvGolang
Install Golang with architecture override for Apple Silicon:
asdf plugin add golang
ASDF_GOLANG_OVERWRITE_ARCH=arm64 asdf install golang latest
asdf global golang latestNode.js
Install Node.js:
asdf plugin add nodejs
asdf install nodejs latest
asdf global nodejs latestTerraform
Install Terraform:
asdf plugin add terraform https://github.com/Banno/asdf-hashicorp.git
asdf install terraform latest
asdf global terraform latestRuby
Install Ruby:
asdf plugin add ruby
asdf install ruby latest
asdf global ruby latestUpdating asdf
Update asdf to the latest version:
asdf updateAdditional Resources
Explore these resources for advanced usage, troubleshooting tips, or to contribute to the asdf community:
- Official Documentation: asdf-vm.com
- GitHub Repository: asdf-vm
- Community Plugins: GitHub Community