Erlang and Elixir on Apple Silicon/M1 Chip

NIce! The “about” link seems to be incorrect though.

thanks, fixed!

Has anyone here had success installing older versions of elixir or OTP?

Using brew to install elixir 1.11 has worked great, but I have some older projects I want to support.

Have you tried with asdf? There is an issue with OTP on BigSur but we can bypass that following https://github.com/asdf-vm/asdf-erlang/issues/161#issuecomment-731558207

1 Like

Getting closer! Trying to install OTP 19.2 these are my results:

Followed this guide to create a rosetta terminal shortcut: https://osxdaily.com/2020/11/18/how-run-homebrew-x86-terminal-apple-silicon-mac/

Followed your link to edit the build and ran all commands in the rosetta terminal: https://github.com/asdf-vm/asdf-erlang/issues/161

Now i’m getting this error:

Build failed.
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/netinet6/in6.h:215:30: note: previous declaration is here
extern const struct in6_addr in6addr_loopback;

Something to do with xcode tools related to this issue: https://github.com/asdf-vm/asdf-erlang/issues/158

So far i’ve gotten 1.11 working using homebrew using the link I posted above. I don’t know if there are any nuances but it seems to be working.

1 Like

I just used Migration Assistant to transfer everything from my 2017 MBP to my new Mac mini. Whatever I had running with Elixir on the old system just works for me. I presume this is Rosetta 2 magic.

I had to launch VSCode twice. The first time the Elixir LS plugin crashed. Second time, no issues.

I’ve not tried to recompile or install the latest version yet. Was holding off for official main branch support because what I have works just fine for now.

2 Likes

I tried this Homebrew: https://github.com/mikelxc/Workarounds-for-ARM-mac

And brew install elixir, and then, I can install Elixir on Arm binary!

% file /opt/homebrew/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/bin/erlexec
/opt/homebrew/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/bin/erlexec: Mach-O 64-bit executable arm64

2 Likes

However, asdf doesn’t work. There are two issues, at least:

  1. It requires brew install curl, but it failed currently because installing sphinx-doc failed.
  2. asdf install erlang 23.1.4 raises an error while configure. To fix it according to https://github.com/asdf-vm/asdf-erlang/issues/161 , tar czvf OTP-23.1.4.tar.gz otp-OTP-23.1.4 doesn’t work due to an error: tar: Failed to clean up compressor
1 Like

I can confirm that installing elixir “just works” on a new Macbook Air M1 with a single brew install elixir for me when installing brew in /opt/homebrew (as advised by homebrew).

4 Likes

I made Elixir work using asdf on my M1 Macbook Air.

  • First setup asdf using the git install method.
  • Add the elixir and erlang plugins.
  • Run asdf install erlang latest this works without any modification.
  • asdf install elixir latest hangs though. To fix it run arch -x86_64 asdf install elixir latest to install with rosetta
2 Likes

A little thread necromancy here.

Decided to update to the M1 homebrew (/opt/homebrew install). Installed adsf. Used asdf to grab the latest Erlang.

And then I was able to use asdf install elixir latest. It worked without caveat.

6 Likes

Also another update from me then :slight_smile:

Most intellij products are updated to M1 versions days ago, so now you can also use their intellij + elixir plugin native on the M1 machines. They came up in the intellij toolbox under a different name next to the old ones e.g. ‘Intellij IDEA Ultimate for Apple Silicon’.

VSCode(+elixirLS) was already working native if you use the ‘exploration’ / insiders build (see https://code.visualstudio.com/insiders/ small download link for ARM64).

4 Likes

I spoke too soon. It would appear that comeonin will compile with an older intel version of elixir (1.10.4-otp-23 in my case) Erlang (23.0.3 in my case), but fails on bcrypt when compiling on the latest elixir 1.11.2-otp-23 Erlang 23.2.1 for apple silicon.

Continuing investigation.

My particular issue was a VSCode architecture mismatch.

Posting the solution here in case anyone else experiences this side effect like I did.

2 Likes

Just wanna say this tutotial is awesome.

1 Like

Very smooth fully native M1 Arm installation now via latest Homebrew and asdf-vm; be sure to install the Erlang dependencies autoconf and wxmac before installing Erlang, as specified in the asdf-erlang instructions.

Of note: the scheduler sees all 8 cores, including the low-power ones:

Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

so it might be interesting to learn how that performs in practice.

6 Likes

Not sure if anyone’s seen this yet, but I’ve installed elixir 1.9 and erlang/otp 23 and almost all elixir compilation errors are swallowed and only a single stack-less “argument error” is spat out, ie:

== Compilation error in file test/support/factory.ex ==
** (ArgumentError) argument error

Even when I compile on the same machine in docker, the compilation errors are reported correctly, so it might actually be a Big Sur issue, but I have no idea as to the root cause.

Hopefully this is of use/interest to someone.

How I got Elixir/Phoenix working on an Apple M1

[MacBook Pro (M1 2020), chip Apple M1, MacOS Big Sur 11.3.1]

I installed the latest Elixir/OTP with Homebrew

$ brew install elixir

but found that my Phoenix projects wouldn’t run.

Eg. GitHub - pdxrod/article_editor
failed with

** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

So I tried starting with a simpler project,

This had a different issue, to do with Mongo and its Elixir driver

{:mongodb, "~> 0.5.1"}

https://hexdocs.pm/mongodb/readme.html

The latest Elixir downloaded by Homebrew was 1.12.1, with Erlang/OTP 24. My project was created using Elixir 1.11.2, with Erlang/OTP 23.

The MongoDb driver 0.5.1 uses crypto.hmac/2, and OTP 24 wants crypto.hmac/3, so the project wouldn’t compile and run.

** (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private

Attempts to upgrade plug_crypto, as recommended here, made no difference.

I couldn’t figure out how to downgrade Elixir and Erlang using Homebrew, asdf, kiex, kurl or exenv. So I deleted all copies of both, and switched to using Macports.

sudo port install erlang @23.1
sudo port install elixir @1.11.2

mix deps.get
mix phx.server

Bingo!

This tells you how to install a given version of something with Macports

I installed Macports by finding MacPorts-2.7.1-11-BigSur.pkg here
Release MacPorts 2.7.1 · macports/macports-base · GitHub downloading and double-clicking on it.

Downgrading to Elixir 1.11 isn’t a permanent solution, so I’m going to look into other Mongo drivers, so see if any of them work with 1.12.

1 Like

The crypto error can be easily addressed too, in case you want to submit a pull request. Here is how it was handled in plug_crypto: Use crypto new API (#20) · elixir-plug/plug_crypto@cf901bd · GitHub

2 Likes