Installing Elixir on Mac M1

Table of Contents

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.

Recommended: Use Nix Instead

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

Note

Before proceeding, make sure:

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

If you try to install Elixir using brew install elixir as suggested in the official docs, it will get installed, but you might face a 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]

How to fix the wxe_wrapper error

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 .

  1. You will find the tarball at ~/.asdf/downloads/erlang/24.0/otp_src_24.0.
  2. Extract the tarball using tar -xzvf otp_src_24.0.tar.gz
  3. Make the changes specified in the above commit in file lib/wx/c_src/gen/wxe_wrapper_5.cpp.
  4. Rebuild the tarball using tar -czvf otp_src_24.0.tar.gz otp_src_24.0.
  5. 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

View all references
Raj Rajhans

Raj Rajhans

Product Engineer with expertise in Elixir & JavaScript ecosystem. Writing about web development, React, Elixir, and more.