OTP 24 compilation error on macOS Monterey 12.3 Mac M1

I’m trying to install erlang version 24.2 on a macbook m1 with macOS 12.3 Monterey and I’m having this compilation error.

Build failed.
/bin/sh: line 1: 55135 Segmentation fault: 11  erlc -W -Werror +debug_info -DUSE_ESOCK=true -DENABLE_MEGACO_FLEX_SCANNER=true -DMEGACO_REENTRANT_FLEX_SCANNER=true -Dmegaco_parser_inline -pa /Users/rrmartins/.asdf/plugins/erlang/kerl-home/builds/asdf_24.2/otp_src_24.2/lib/et/ebin -pa /Users/rrmartins/.asdf/plugins/erlang/kerl-home/builds/asdf_24.2/otp_src_24.2/lib/megaco/ebin +'{parse_transform,sys_pre_attributes}' +'{attribute,insert,app_vsn,"megaco-4.2"}' -I../../include -o../../ebin megaco_flex_scanner.erl
make[5]: *** [../../ebin/megaco_flex_scanner.beam] Error 139
make[5]: *** Waiting for unfinished jobs....
/bin/sh: line 1: 55134 Segmentation fault: 11  erlc -W -Werror +debug_info -DUSE_ESOCK=true -DENABLE_MEGACO_FLEX_SCANNER=true -DMEGACO_REENTRANT_FLEX_SCANNER=true -Dmegaco_parser_inline -pa /Users/rrmartins/.asdf/plugins/erlang/kerl-home/builds/asdf_24.2/otp_src_24.2/lib/et/ebin -pa /Users/rrmartins/.asdf/plugins/erlang/kerl-home/builds/asdf_24.2/otp_src_24.2/lib/megaco/ebin +'{parse_transform,sys_pre_attributes}' +'{attribute,insert,app_vsn,"megaco-4.2"}' -I../../include -o../../ebin megaco_flex_scanner_handler.erl
make[5]: *** [../../ebin/megaco_flex_scanner_handler.beam] Error 139
make[4]: *** [opt] Error 2
make[3]: *** [opt] Error 2
make[2]: *** [opt] Error 2
make[1]: *** [opt] Error 2
make: *** [libs] Error 2

These seem to be errors related to megaco rather than Erlang? I have no knowledge of megaco and had to google it. I have had no issues with OTP 24 or OTP 25 RC installs on my M1-based system hence my conjecture about megaco-related configuration being the issue.

Your error message looks similar to the ones here:

Make sure you’ve got the latest build of kerl if you’re using it.