Using ASDF-vm

Solve All of Your Version Problems

Nerves usually pushes the bleeding edge of Elixir, which means we sometimes sometimes hear about problems in our Nerves Slack channel that can be solved by updating to the latest version of Elixir and OTP. Now, there are built-in options in most operating systems to do this, such as brew, apt-get, pacman etc, and they all work with varying levels of success. ASDF-vm is an alternate version manager that allows easy installation and switching between different versions of various packages.

Managing Elixir and Erlang with ASDF-vm

Let’s go through how easy it is to set up Elixir and Erlang with ASDF.

Installation

First, install asdf. There are many ways to do this, so check out the official instructions for what is best for you.

Then you will want to install the plugins for both Erlang and Elixir.

Install plugins

asdf plugin-add erlang
asdf plugin-add elixir

Choose versions

# Build and install Erlang/OTP
asdf install erlang 26.1.1

# Install Elixir 1.15 as compiled against Erlang/OTP 26
asdf install elixir 1.15.6-otp-26

Setup

The following sets the Erlang and Elixir versions system-wide.

asdf global erlang 26.1.1
asdf global elixir 1.15.6-otp-26

If you want to fix the version used in a directory, specify local:

asdf local erlang 26.1.1
asdf local elixir 1.15.6-otp-26

The local option works by creating or updating a .tool-versions file in the directory.

Updating

When a new stable release comes out, you can do similar commands. Here’s a currently hypothetical OTP 99/Elixir 2.0 example:

asdf install erlang 99.0
asdf install elixir 2.0.0-otp-99

asdf global erlang 99.0
asdf global elixir 2.0.0-otp-99

Then, if that were to break, you can simply change back:

asdf global erlang 26.1.1
asdf global elixir 1.15.6-otp-26

Nerves

The Nerves Project currently builds ERTS (Erlang Run Time System) into the officially-supported systems. The build tools will throw an error if the host machine’s OTP version doesn’t match the version built into the system for your target. This is done to ensure you can develop your application on your host machine, then push to your embedded device and everything will work as expected. This is where a version manager really comes in handy. Instead of sifting thru .deb files, or trying to install a newer or older version of OTP using your operating system’s package manager, you can run two commands that explicitly explain the version of a package you want.

nerves 
comments powered by Disqus