How to run Erlang natively on Apple M1 chip.
If you are using version 23+, just upgrade your version to 23.2+ then you are able to build and install via package management tools like kerl, homebrew, asdf … etc.
If you’re using some legacy versions, then this article might help you.
I used kerl
to build and install Erlang on my Mac,
Build Erlang from kerl
you might see the following error the first time.
~/code » kerl build 21.3.8.19 21.3.8.19 130
lvshaochun@lvshaochundeMacBook-Pro
/Users/lvshaochun/.kerl/archives/OTP-21.3.8.19.tar.gz corrupted and redownloading...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 125 100 125 0 0 365 0 --:--:-- --:--:-- --:--:-- 364
100 51.5M 0 51.5M 0 0 4254k 0 --:--:-- 0:00:12 --:--:-- 4639k
Extracting source code
Building Erlang/OTP 21.3.8.19 (21.3.8.19), please wait...
Configure failed.
checking OTP release... 21
checking OTP version... 21.3.8.19
configure: error:You are natively building Erlang/OTP for a later version of MacOSX
than current version (11.1). You either need to
cross-build Erlang/OTP, or set the environment variable
MACOSX_DEPLOYMENT_TARGET to 11.1 (or a lower version).Please see /Users/lvshaochun/.kerl/builds/21.3.8.19/otp_build_21.3.8.19.log for full details.
Now we need to do some patch into the source code.
- Go to the source code folder.
~/code » cd /Users/lvshaochun/.kerl/builds/21.3.8.19/otp_src_21.3.8.19/
2. configure.in
file around Line 400, please add && false
after int_macos_version
like the following code block.
400 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > $int_macosx_version && false
401 #error Compiling for a newer MacOSX version...
402 #endif
3. Then we need to patch code by the following PRs.
https://github.com/erlang/otp/pull/2687
(Note: About 2700 PR the change of erts/aclocal.m4
is in erts/configure.in
when you change Erlang OTP 20 series.
https://github.com/erlang/otp/pull/2700
https://github.com/erlang/otp/pull/2708
3. Build with the same command again kerl build 21.3.8.19
, then you will see the Erlang is building like the following code block.
~/.kerl/builds/21.3.8.19/otp_src_21.3.8.19 » kerl build 21.3.8.19 21.3.8.19Extracting source code
Building Erlang/OTP 21.3.8.19 (21.3.8.19), please wait...
APPLICATIONS DISABLED (See: /Users/lvshaochun/.kerl/builds/21.3.8.19/otp_build_21.3.8.19.log)
* jinterface : No Java compiler found
* odbc : ODBC library - link check failedAPPLICATIONS INFORMATION (See: /Users/lvshaochun/.kerl/builds/21.3.8.19/otp_build_21.3.8.19.log)
* wx : wxWidgets not found, wx will NOT be usableDOCUMENTATION INFORMATION (See: /Users/lvshaochun/.kerl/builds/21.3.8.19/otp_build_21.3.8.19.log)
* documentation :
* fop is missing.
* Using fakefop to generate placeholder PDF files.Erlang/OTP 21.3.8.19 (21.3.8.19) has been successfully built
Install Erlang from kerl.
Command: kerl install 21.3.8.19 ~/.kerl/21.3.8.19
~/.kerl/builds/21.3.8.19/otp_src_21.3.8.19 » kerl install 21.3.8.19 ~/.kerl/21.3.8.19
Installing Erlang/OTP 21.3.8.19 (21.3.8.19) in /Users/lvshaochun/.kerl/21.3.8.19...
You can activate this installation running the following command:
. /Users/lvshaochun/.kerl/21.3.8.19/activate
Later on, you can leave the installation typing:
kerl_deactivate
Congratulations
Enjoy the native speed.
A soft reminder, the Erlang development team only supports 2 major releases, please update your Erlang version update to date.
I also upload the patched code on GitHub(you can check the difference with the following link).
https://github.com/oslo0322/erlang_on_m1/commit/e0c2fd8a2cf8b53f8c0e6ffe54ed966ba3281fdc