How to Manage Elixir versions on Mac or Linux — Part 2 of Getting Started with Elixir

⚠️ This is the second article in a 2-part series
→️ Click here if you missed Part 1 :)

Elixir is a wonderful language. Expressive, productive, scalable, fault-tolerant… it’s pretty darn cool. But how do we manage projects which use different versions?

Enter asdf.

🤔 What have we done so far?

In part 1, we got quite a lot done:

  1. Installed asdf version manager
  2. Installed the Erlang & Elixir plugins for asdf:
  3. Installed Erlang 19.3 and Elixir 1.3.4 using asdf
  4. Set asdf to use Erlang 19.3 and Elixir 1.3.4 globally (using the global keyword)
  5. Created a new project using Elixir 1.3.4
  6. Told asdf to always use Elixir 1.3.4 and Erlang 19.3 for our new project (using the local keyword)

🚀 What’s next?

This final chapter is going to be pretty straightforward:

  1. Install Erlang 21.1 and Elixir 1.7.4 (the latest versions at the time of writing)
  2. Tell asdf to use the new versions of Erlang & Elixir globally

🆕 1. Installing Erlang 21.1 and Elixir 1.7.4

We want to install the latest version of Elixir. Right now (4 Jan 2019), the latest version of Elixir is 1.7.4, so that’s what we’ll use.

Wait, what version of Erlang do we need for Elixir 1.7.4?
A table of Erlang & Elixir version compatibilities, as of 4 Jan 2019

According to the table above (found on this page), Elixir 1.7 requires Erlang versions 19 to 21. So we’ll first install Erlang 21.1. Then when that’s done, we’ll install Elixir 1.7.4.

  1. Open up Terminal
  2. Install Erlang 21.1:
asdf install erlang 21.1

This will take a while because asdf needs to download and build Erlang from scratch. Don’t worry if you’re waiting 5 or 10 minutes. It’ll get there in the end. ⏳

3. Install Elixir 1.7.4:

asdf install elixir 1.7.4
Okay, Erlang and Elixir are both installed. We should be done now, right?

Not yet, but we’re close!

🌏 2. Telling asdf to use our new versions of Erlang & Elixir globally

To finish things off, we need to tell asdf to use our new versions of Erlang & Elixir globally:

asdf global erlang 21.1
asdf global elixir 1.7.4
What have we just done there?

We’ve told asdf to use Erlang 21.1 and Elixir 1.7.4 any time we run an Erlang or Elixir command if the folder doesn’t have a .tool-versions file to specify which version to use.

So effectively, we’re now using Erlang 21.1 and Elixir 1.7.4 by default.

Now we have just one thing left to do: test it!

  1. Move back to our user directory (because our command might use the wrong version if we’re in a project containing a .tool-versions file):
cd ~

2. Check your Elixir version:

elixir -v

Hopefully you’ll see get an output similar to this:

Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Elixir 1.7.4 (compiled with Erlang/OTP 21)

Perfect! You’re now ready to go with Elixir and Erlang.

How to set a global language version… and a reminder to make sure you’re not inside your project folder when you run `elixir -v` :)

📜 Summary / Cheat sheet

Fantastic. We’re now in a fantastic position to take on any project (no matter what version of Elixir it requires!) and start pushing out code.

Here’s a handy cheat sheet of the commands we’ve been using throughout parts 1 and 2:

# install elixir plugin for asdf
asdf plugin-add elixir

# install elixir 1.7.4 using asdf
asdf install elixir 1.7.4

# tell asdf to use elixir 1.7.4 globally
asdf global elixir 1.7.4

# tell asdf to use elixir 1.3.4 locally (when we're in the folder for a project)
asdf local elixir 1.3.4

# check what version of Elixir we're using
elixir -v

I’ve only added Elixir commands here because their Erlang counterparts are very similar

Thanks for reading! I hope you’ve found these how-to articles helpful :)

  • Found this article helpful? Claps or comments are always appreciated :)
  • Got stuck? Leave a comment; I’ll do my best to help!
  • Have an idea on how this article could be improved? Please let me know in a comment! I’m a big fan of constructive feedback :)