Installing Node, Elixir and Python using asdf on macOS

This year I stumbled quite often across the tool asdf. At the moment, It seems to be the goto tool to manage multiple runtime versions. An intriguing aspect is that it is one tool to manage all kinds of runtime environments. I got a bit annoyed from using pyenv, nvm, Homebrew and so on to manage my Python, Node and Elixir installations lately. A good time to give asdf a try and it just works!

This tutorial assumes you have Homebrew installed on your Mac already.

Installing asdf and dependencies

First of we install asdf itself and some common dependencies of the runtimes to be installed.

brew install asdf coreutils automake autoconf \ openssl libyaml readline libxslt libtool curl git

Next, you have to add asdf to your shell. Here is the code for Fish, Bash and ZSH.

# Fish echo -e "\nsource "(brew --prefix asdf)"/asdf.fish" >> ~/.config/fish/config.fish # Bash echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ~/.bash_profile # ZSH echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ~/.zshrc

Now you have to restart your shell to activate the changes.

Installing Node

To use the asdf node plugin, you have to install gpg first, because it validates the gpg keys of the release. And you also have to import the gpg keys of the release team.

brew install gpg bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring'

Next you have to install the asdf plugin for Node.

asdf plugin add nodejs

Finally, you can install the desired version of node and activate it globally. You can pick any version you desire. I prefer to use the LTS releases of Node.

asdf install nodejs latest:12 asdf global nodejs 12.19.0

You can retrieve a list with all available Node versions with the following command.

asdf list all nodejs

Installing Python

Installing Python is way easier than installing Node. You have to add the asdf plugin, install your desired version and activate it globally. ❤️

A neat feature of the plugin, if you still need to support Python 2, you can specify two versions on the asdf global call. Check out the README of the plugin.

asdf plugin add python asdf install python 3.9.0 asdf global python 3.9.0

You can retrieve a list with all available Python versions with the following command.

asdf list all python

Installing Erlang & Elixir

Installing Erlang and Elixir is again a bit more complicated. First of we have to install some dependencies to built Erlang.

brew install unixodbc wxmac fop

Next you have to install the asdf plugin as usual. In this case you have to install two plugins – one for Erlang and one for Elixir.

asdf plugin add erlang asdf plugin add elixir

Now, we are ready to install Erlang and activate it globally. To support the new IEx feature from Elixir 1.11 we have set the environment variable KERL_BUILD_DOCS.

export KERL_BUILD_DOCS=yes asdf install erlang 23.1.1 asdf global erlang 23.1.1

We installed Erlang 23, so we also want to install the Elixir version that is optimized for the corresponding OTP version.

asdf install elixir 1.11.1-otp-23 asdf global elixir 1.11.1-otp-23

In case you have installed Hex and Phoenix before, you have to install them again. The mix version that gets installed via asdf doesn’t use the .mix directory from your home directory. Every installation of Elixir has its own .mix directory.

You can retrieve a list with all available Erlang and Elixir versions with the following commands.

asdf list all erlang asdf list all elixir