Skip to content

Instantly share code, notes, and snippets.

@nilsalm
Last active April 17, 2022 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nilsalm/059cb565e14f85ff9804e3434967cd95 to your computer and use it in GitHub Desktop.
Save nilsalm/059cb565e14f85ff9804e3434967cd95 to your computer and use it in GitHub Desktop.
Installing Elixir on Mac M1 July 2021

Installing Elixir on Mac M1 July 2021

I recently got excited about functional programming and wanted to learn more and then my friend recommended I check out Elixir. I tried to install it and got stuck for so many hours that I nearly gave up. Nearly. Here's how I pulled it together, if I remember the steps correctly

How it didn't work

First, I was so excited that I just jumped on youtube and followed a tutorial from 2017 that started with installing Erlang from their official homepage. That didn't quite work once I tried brew install elixir so I got rid of that erlang again and installed the whole thing through homebrew. This continued to give me Segmentation Faults every time I started erl or elixir -v.

How it worked in the end

First off, this answer on stack exchange was tremendous help.

In essence, I installed homebrew two times:

  • /usr/local for macOS Intel
  • /opt/homebrew for macOS ARM (i.e. the M1)

Since homebrew now supports the ARM, you should be able to execute the installation command from their homepage basically anywhere BUT with an important difference: you have to do it once with Rosetta enabled for your terminal and once without. (To toggle that, find your terminal-application in the Applications on your Mac, press CMD+i and click "Open using Rosetta")

Then create aliases like the following in your respective config, mine was .zshrc, yours might be .bashrc. Open up that file and copy the following in, save and make sure to run source .zshrc afterwards to make the changes available.

alias ibrew='arch -x86_64 /usr/local/bin/brew'
alias mbrew='arch -arm64e /opt/homebrew/bin/brew'

Add the paths also to your $PATH, mine looks like this now:

/opt/homebrew/bin
/opt/homebrew/opt
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

I then opened my terminal with Rosetta enabled and used the mbrew-alias to finally install elixir: mbrew install elixir. This is the part that I don't actually understand as mbrew was supposed to be for the ARM, but then I run the terminal in Intel mode, and this works? Please explain.

For the record, here's the output:

mbrew install elixir
==> Downloading https://ghcr.io/v2/homebrew/core/erlang/manifests/24.0.3
Already downloaded: /Users/nils/Library/Caches/Homebrew/downloads/027550f618a59746484f459f55e84ef651985d2fb6a069db89de6811bf81f9e2--erlang-24.0.3.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/erlang/blobs/sha256:8ebaae00022e7bb359df1fac2a45ecb371cb5cc96b69d18f6
Already downloaded: /Users/nils/Library/Caches/Homebrew/downloads/5c53a77440f083d502206706a014e2edb930a1e6c3afdc0d892e4be24b010896--erlang--24.0.3.arm64_big_sur.bottle.tar.gz
==> Downloading https://ghcr.io/v2/homebrew/core/elixir/manifests/1.12.2
Already downloaded: /Users/nils/Library/Caches/Homebrew/downloads/8626a537d9ef8c8557b438f56bafa283c3118c22fd446f8b6eed37833a19a5a7--elixir-1.12.2.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/elixir/blobs/sha256:9931199e37b5ed93b73b10cbbea910f735d537d935f7e0609
Already downloaded: /Users/nils/Library/Caches/Homebrew/downloads/edbddd60e0d95dd14a7781aaa07aea59aabc993ba813d73d7b0172b53db17140--elixir--1.12.2.arm64_big_sur.bottle.tar.gz
==> Installing dependencies for elixir: erlang
==> Installing elixir dependency: erlang
==> Pouring erlang--24.0.3.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/erlang/24.0.3: 7,619 files, 482.9MB
==> Installing elixir
==> Pouring elixir--1.12.2.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/elixir/1.12.2: 434 files, 6.4MB
erl
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [dtrace]

Eshell V12.0.3  (abort with ^G)
elixir -v
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [dtrace]

Elixir 1.12.2 (compiled with Erlang/OTP 24)

My hope in sharing this learning is is to help a fellow struggling enthusiast to get started or to receive a comment from a more experienced fellow explaining what caused me so much trouble and maybe advising an easier way forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment