Installing Elixir on Mac M1

By Raj Rajhans -
October 5th, 2022
6 minute read

Recently, I decided to start learning Elixir. The first step in learning any language is to install the required tools. While installing elixir on a mac m1 machine, I ran into a lot of problems. This post is a quick guide on the issues I faced and how to fix them.

In retrospect, I should have not installed Elixir directly but should have installed Elixir via Nix. If you want a guide on that, check out this post by Rakshan.

If you anyway want to install Elixir directly, read on to find out the issues I faced. Hopefully, most of these issues should be fixed, but as of writing this post (October 2021), these issues are still present.

Things to make sure before installing Elixir


  • Make your you are not in a Rosetta shell. Also make sure that your brew is pointing to /opt/homebrew/bin/brew.
  • Make sure you have the latest version of command line tools is installed. Run softwareupdate --all --install --force to update it.
  • Make sure you have installed asdf.

If you try to install Elixir using brew install elixir as suggested in the official docs, it will get installed, but you might face segmentation fault after installing and running elixir --version. If that’s happening to you as well, check out this StackOverflow Question.

These are the steps you need to follow:

  1. Install asdf if you haven’t already.
  2. Install the asdf erlang plugin.
    • Make sure to read the “Before asdf install” section.
    • asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
  3. Run asdf install erlang latest and wait for erlang to build.
  4. Run asdf global erlang latest
  5. Install the asdf elixir plugin.
    • asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
  6. Install Elixir asdf install elixir latest
  7. asdf global elixir latest
  8. Run iex or elixir --version to test the installation.

Issues you might face while following the above steps


While trying to install Erlang, I faced a OpenSSL error -

checking for OpenSSL in /usr/local/opt/[email protected]... configure: error: neither static nor dynamic crypto library found in /usr/local/opt/[email protected]

This can be fixed by adding KERNEL CONFIG FLAG KERL_CONFIGURE_OPTIONS="--disable-parallel-configure"

I faced another error after fixing this one -

gen/wxe_wrapper_5.cpp:2165:29: error: taking the address of a temporary object of type 'wxBitmap' [-Waddress-of-temporary]

  • This error is happening due to a problem in the code, as discussed in this github issue.
  • To fix this, you need to overwrite the OTP tarball that asdf gives us with the fix in this commit.
  • You will find the tarball at ~/.asdf/downloads/erlang/24.0/otp_src_24.0.
  • Extract the tarball using tar -xzvf otp_src_24.0.tar.gz
  • Make the changes specified in the above commit in file lib/wx/c_src/gen/wxe_wrapper_5.cpp.
  • Rebuild the tarball using tar -czvf otp_src_24.0.tar.gz otp_src_24.0.
  • Now, run asdf install erlang latest again.

If you face any more errors that mention openssl or java, update the KERL_CONFIGURE_OPTIONS -

export KERL_CONFIGURE_OPTIONS="--with-ssl=/opt/homebrew/opt/[email protected] \
--with-wx-config=/opt/homebrew/opt/[email protected]/bin/wx-config \
--without-javac"

After this, Erlang should be installed. Install elixir as mentioned in the above steps. Make sure the elixir version u are installing is compatible with the erlang version you have installed. You can find the compatibility table here.

References


raj-rajhans

Raj Rajhans

Product Engineer @ invideo
Tags