← All Posts

Polyglot Version Management with asdf

Dabbling in multiple programming languages can be a lot of fun. However, because each language tends to have its own version manager, remembering each version manager’s commands can get a little cumbersome. This is why the idea of having a single version manager for all of your languages is very intriguing. Asdf is a version manager that aims to do that. It supports a large number of languages, all with only one set of commands to remember.

Let’s get it installed, add a language plugin, then activate the desired language version.

Installation

Installation is performed using either Homebrew on macOS or Git on Linux.

# macOS
> brew install asdf
# Linux
> git clone https://github.com/asdf-vm/asdf.git ~/.asdf

You must then source the script by adding the following line to your ~/.zshrc, ~/.bashrc, or ~/.bash_profile.

. ~/.asdf/asdf.sh

See the latest documentation if more detail is needed.

Usage

Asdf has the concept of “plugins” for each supported language. We need to install a plugin for any language we want to use.

First, let’s list all available plugins using asdf plugin-list-all.

> asdf plugin-list-all
golang          https://github.com/kennyp/asdf-golang.git
nodejs          https://github.com/asdf-vm/asdf-nodejs.git
python          https://github.com/danhper/asdf-python.git
ruby            https://github.com/asdf-vm/asdf-ruby.git
# many more...

From the list, let’s add the Node.js plugin.

> asdf plugin-add nodejs

Once the plugin is added, we can list all versions available to us.

> asdf list-all nodejs
12.16.0
12.16.1
12.16.2
12.16.3
12.17.0
12.18.0
12.18.1
# many more...

Any version from the list can be installed, we’ll install the latest LTS.

> asdf install nodejs 12.18.1

Once installed, we declare this version as the one we’d like to use globally on our system.

> asdf global nodejs 12.18.1

If you need to run a specific version only for a single project, we can do that using the asdf local command.

> cd node-10-project
> asdf local nodejs 10.21.0

This will create a file named .tool-versions that specifies which version should be used within the current project. Asdf will automatically detect and use that version if it is installed.

The above steps can be repeated for any language we’d like.

All plugins and versions installed can be viewed with the asdf list command.

> asdf list
golang
  1.14
  1.15beta1
nodejs
  10.21.0
  12.18.1
python
  3.8.2
  3.10-dev
ruby
  2.7.0
  2.8.0-dev

Summary

Asdf is a very powerful tool that can replace aany number of version managers. I’d highly recommend using it if you use more than a couple languages on your system and have a need to switch between versions. Head on over to their documentation if you’d like to learn more.