Would be nice if there was a way inside of Erlang/OTP to build standalone executables

Going off of this Hacker News comment: Writing your own BEAM | Hacker News

The BEAM is fascinating for many reasons, including being register-based.

I really just wish the BEAM was portable in the way the JVM is. The BEAM hooks into so many system libraries, you must compile it on every flavor of linux instead of just unpacking a tarball.

This means you either must use your distro package manager’s version, or compile from scratch. If you want to control the exact version that’s being used across your team (via asdf or similar), this practically means you’ll end up compiling the BEAM over and over…

It would be nice for BEAM based applications to compile standalone executables.

And before anyone asks, I am aware of GitHub - burrito-elixir/burrito: Wrap your application in a BEAM Burrito! thought that requires Zig (and I think is Elixir only?)

4 Likes

Couldn’t a docker image a la: GitHub - erlang/docker-erlang-example: HowTo Erlang in Docker be an alternative?

This isn’t true! One can statically link the BEAM on Linux the same way as you can the JVM. Here’s an example: GitHub - yoshi-monster/static_erlang: A static binary distribution of Erlang/OTP.

The standard Windows and macOS builds are already portable too.

The BEAM start scripts are very convoluted though, which I think is why tools like burrito take the approach of using self-extracting archives. Yoshie was looking at making a true single-file executable with her static Linux build, she spoke about it at her CodeBEAM Europe lightning talk this year.

5 Likes

This is amazing. I verified it working on ancient ubuntu and glibc vs musl below:

$ docker run --rm -it -v /tmp/otp:/tmp/otp ubuntu:24.04 /tmp/otp/bin/erl -eval 'io:format("~p~n", [crypto:strong_rand_bytes(10)]), halt().'
<<44,21,251,21,125,116,17,139,243,247>>

$ docker run --rm -it -v /tmp/otp:/tmp/otp ubuntu:14.04 /tmp/otp/bin/erl -eval 'io:format("~p~n", [crypto:strong_rand_bytes(10)]), halt().'
<<236,8,88,195,169,117,20,138,147,44>>

$ docker run --rm -it -v /tmp/otp:/tmp/otp alpine:latest /tmp/otp/bin/erl -eval 'io:format("~p~n", [crypto:strong_rand_bytes(10)]), halt().'
<<65,187,207,104,67,55,146,210,147,249>>
2 Likes

It really is! If we can make this dependable and maintained for the long-term it would make getting started with BEAM languages much smoother. Currently installing Erlang on Linux is one of the things that people get stuck with.

5 Likes

This is genuinely fantastic!
Just saw the lightning talk.
Kudos.

Since there seems to be interest in this feature, I went ahead and made a github issue on the OTP repository for this:

1 Like