DEV Community 👩‍💻👨‍💻

Susumu Yamazaki
Susumu Yamazaki

Posted on • Updated on

Perfect Steps of Installing Erlang and Elixir to Apple Silicon Mac (2021 Dec edition)

In this article, I'll show the perfect steps of installing Erlang and Elixir to Apple Silicon Mac from scratch using Homebrew and asdf.

1. Upgrade macOS (if M1)

You can skip this step for M1 Pro/Max.

If M1, pre-installed macOS is Big Sur. So, first of all, you need to upgrade macOS into Monterey 12.1. However, upgrading from the pre-installed macOS Big Sur to Monterey will be failed due to the defect of the installer of Monterey. So, you should update Big Sur as the first step. Next, upgrade it into Monterey 12.0.1. Next, update it into Monterey 12.1.

2. Install Xcode 13.2.1 (optional)

You can skip this step even though you will install Homebrew.

Install Xcode 13.2.1 by App store.

3. Install Homebrew

  1. Launch terminal.
  2. Install Homebrew according to the official website.
  3. Run commands shown in the output results after installation.

The commands mentioned above are as follows (it requires your login password by sudo):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ${ZDOTDIR:-~}/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Enter fullscreen mode Exit fullscreen mode

Be sure to check and use the installation procedure on the official website and the commands displayed after installation.

4. Install Erlang and Elixir by Homebrew

Run the following commands at the terminal:

brew update
brew install elixir
Enter fullscreen mode Exit fullscreen mode

These commands install the latest Erlang and Elixir. If you use only the latest ones, these commands will be the easiest.

4'. Install only Erlang by Homebrew

If you want to install only Erlang, run the following commands at the terminal:

brew update
brew install erlang
Enter fullscreen mode Exit fullscreen mode

4''. Install Erlang and Elixir by asdf

Unfortunately, the installation procedure on the official website gets incomplete: unlinked to wx and odbc, lack of documents, etc.

4''-1. Install asdf by Homebrew

Install asdf by Homebrew according to the official website. I'll show the commands as follows, but you should check the official website:

brew install asdf
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc
source ${ZDOTDIR:-~}/.zshrc
Enter fullscreen mode Exit fullscreen mode

4''-2. Install Erlang by asdf

This step is the most important. Firstly, install pre-requisite libraries:

asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
brew install wxwidgets
brew install openjdk
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ${ZDOTDIR:-~}/.zshrc
source ${ZDOTDIR:-~}/.zshrc
brew install fop
Enter fullscreen mode Exit fullscreen mode

Then, set the environment variables KERL_CONFIGURE_OPTION, CC and LDFLAGS as follows:

export KERL_CONFIGURE_OPTIONS="--with-ssl=$(brew --prefix openssl@1.1) --with-odbc=$(brew --prefix unixodbc)"
export CC="/usr/bin/clang -I$(brew --prefix unixodbc)/include" 
export LDFLAGS=-L$(brew --prefix unixodbc)/lib
Enter fullscreen mode Exit fullscreen mode

If you will install Erlang/OTP 24.2+ and use OpenSSL 3, install OpenSSL 3 and reset KERL_CONFIGURE_OPTION:

brew install openssl@3
export KERL_CONFIGURE_OPTIONS="--with-ssl=$(brew --prefix openssl@3) --with-odbc=$(brew --prefix unixodbc)"
Enter fullscreen mode Exit fullscreen mode

I got the solution to link odbc by referring this issue: https://github.com/asdf-vm/asdf-erlang/issues/191

Next, if you'll install the latest one, run the following commands:

asdf install erlang latest
asdf global erlang latest
Enter fullscreen mode Exit fullscreen mode

You can get the versions that can be installed as follows:

asdf list-all erlang
Enter fullscreen mode Exit fullscreen mode

Unfortunately, some specific older versions cannot be installed into Apple Silicon Mac.

If you'll install OTP 22, follow this issue: https://github.com/asdf-vm/asdf-erlang/issues/221

After installation, unset CC and LDFLAGS:

unset CC LDFLAGS
Enter fullscreen mode Exit fullscreen mode

4''-3. Install Elixir by asdf

Install the Elixir plugin by asdf according to the official website.

asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
Enter fullscreen mode Exit fullscreen mode

Next, if you'll install the latest one, run the following commands:

asdf install elixir latest
asdf global elixir latest
Enter fullscreen mode Exit fullscreen mode

You can get the versions that can be installed as follows:

asdf list-all elixir
Enter fullscreen mode Exit fullscreen mode

Summary

You'll get Elixir and Erlang on Apple Silicon as the steps mentioned above.

Top comments (2)

Collapse
 
dddhuang profile image
DDDHuang

Great solution to the M1 problem. Awesome

Collapse
 
dongseok0 profile image
Dongseok Paeng

I had to add --without-wx as well in KERL_CONFIGURE_OPTIONS but finally it worked. Thanks!!

We are hiring! Do you want to be our Senior Platform Engineer? We're hiring for a Senior Platform Engineer and would love for you to apply.

Head here to learn more about who we're looking for.