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
- Launch terminal.
- Install Homebrew according to the official website.
- 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)"
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
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
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
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
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
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)"
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
You can get the versions that can be installed as follows:
asdf list-all erlang
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
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
Next, if you'll install the latest one, run the following commands:
asdf install elixir latest
asdf global elixir latest
You can get the versions that can be installed as follows:
asdf list-all elixir
Summary
You'll get Elixir and Erlang on Apple Silicon as the steps mentioned above.
Top comments (5)
Great solution to the M1 problem. Awesome
This is what I had to do:
Then SSL worked properly, from here: github.com/kerl/kerl/issues/320#is...
I had to add
--without-wx
as well in KERL_CONFIGURE_OPTIONS but finally it worked. Thanks!!Thank you for this guide! M3 mac in 2023 here: I had to add
--disable-jit
toKERL_CONFIGURE_OPTIONS
to succeed installing Erlang 25 (one version older than current newest version)More than a year and a half later, I keep coming back here to get my ass saved every time I need to upgrade my Elixir and Erlang versions 😄 Thanks a lot for this.