Using asdf Version Manager

Replace all your runtime version managers with a single CLI tool

Aug 15, 2024    m. Sep 14, 2024    #runtimes  

Introduction

An app can get quite complicated: your microservice needs Go v1.1, your backend needs Python v3.2, and your NextJS frontend needs Node v18 - different runtimes and different versions, typically managed by their own individual runtime managers - an absolute trouble when running on your local machine!

There is, however, an alternative - a single tool that allows managing multiple runtime versions - asdf.

What is asdf

asdf is a universal version manager that supports a wide array of programming languages and tools through plugins. Unlike other version managers that are often language-specific, asdf provides a single interface to manage versions across various ecosystems, including Ruby, Node.js, Python, and more.

Key Features

How to install

As per installation instructions , the first step is to install dependencies (using Mac as dev machine):

brew install coreutils curl git

Next, we install asdf using homebrew:

brew install asdf

Once done, we can add asdf.sh script to ~./zshrc:

echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

Finally, we can restart the shell so that PATH changes take effect - simply re-open the terminal tab will do it.

How to use

To start using asdf, we can start by installing our first plugin. Head over to the master list of asdf plugins here .

As each plugin will require installation of its own dependcies, it is best to follow the installation guide of each plugin.

Installing Erlang & Elixir

In this example, we will install Elixir and Erlang for demonstration purposes.

We start by installing Erlang dependencies:

brew install autoconf # build tool
brew install openssl
brew install wxwidgets
brew install libxslt fop

Next, we need to determine which Erlang OTP version we need for the Elixir version we want to install. We can find it from the official docs :

Elixir Version Erlang OTP version
1.17 25-27

We can now add the erlang plugin to asdf:

asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git

To avoid OpenSSL issues when using asdf to install erlang, we can run this in the terminal:

export KERL_CONFIGURE_OPTIONS="--without-javac --with-ssl=$(brew --prefix [email protected])"

Now, we can install erlang version 27:

asdf install erlang 27

Next, we can add the elixir plugin to asdf:

asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git

Finally, we can install Elixir v1.17:

asdf install elixir latest #v1.17 is the latest at time of writing

We can now set versions globally or locally (inside project folder):

asdf global elixir latest
# or locally in project folder
asdf local elixir 1.17

We can verify this in terminal:

> elixir -v
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.17.0 (compiled with Erlang/OTP 27)

To keep plugins and asdf up to date, we can do:

asdf update
asdf plugin update --all
# or
asdf plugin update <specific plugin>

To remove a plugin, we can do:

asdf plugin remove <specific plugin>

To get the full list of asdf commands, you can do:

asdf help

Caveats

If your runtime has its own runtime manager with first-class support, such as Rust’s rustup , it may be advisable to stick to using that instead.

Conclusion

asdf simplifies the management of multiple versions across different languages and tools, streamlining your development workflow. By leveraging its plugin-based architecture and straightforward command-line interface, developers can maintain a clean and organized environment, enhancing productivity and consistency. Whether you’re managing multiple projects or transitioning between different tool versions, asdf offers a flexible solution to meet your needs.



Next: Is it possible to use an apartment as collateral for a loan on Compound?