# How to merge multiple beam files into one beam?

**URL:** <https://erlangforums.com/t/how-to-merge-multiple-beam-files-into-one-beam/5339>\
**Category:** Questions / Help\
**Tags:** erlang, code\
**Created:** [December 25, 2025, 6:03am UTC](https://erlangforums.com/t/how-to-merge-multiple-beam-files-into-one-beam/5339 "2025-12-25T06:03:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominic](https://erlangforums.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@dominic](https://erlangforums.com/u/dominic)\
**Post date:** [December 25, 2025, 6:03am UTC](https://erlangforums.com/t/how-to-merge-multiple-beam-files-into-one-beam/5339/1 "2025-12-25T06:03:21Z")

</div>

I’m using `.beam` as script file, then I can hidden my code and run every where.

Usually, there are multiple files work together like:

```erlang
main.erl
util.erl
....

```

Is it possible to merge multiple beam files into one beam?

What I can think of is to hardcode the beam into an erl file and then compile it, like

```erlang
["[",
lists:map(fun(Beam) ->
  {ok, Bin} = prim_file:read_file(Beam),
  ["{", filename:basename(Beam, ".beam"), ",", io_lib:format("~w", [Bin]), "},"]
end, BeamList)
"ok]"]

```

get

```erlang
[{module, <<"....">>}]

```

finally, use `code:load_file` to load it

---

<div class="post-metadata">

**Author:** ![ieQu1](https://erlangforums.com/user_avatar/erlangforums.com/iequ1/32/2633_2.png) [@ieQu1](https://erlangforums.com/u/ieQu1)\
**Post date:** [December 25, 2025, 6:28am UTC](https://erlangforums.com/t/how-to-merge-multiple-beam-files-into-one-beam/5339/2 "2025-12-25T06:28:19Z")

</div>

> I can hidden my code and run every where

.beam files are not entirely portable. Erlang VM cannot load files compiled by newer version of OTP, or too old of a version.

> I’m using `.beam` as script file

Common solution to your problem is [escript](https://www.erlang.org/doc/apps/stdlib/escript.html), a type of an archive that can include multiple beam files, as well as Erlang runtime. Erlang runtime comes with an `escript` executable that knows how to extract and run these archives. `rebar3` supports building escripts.

---

<div class="post-metadata">

**Author:** ![dominic](https://erlangforums.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@dominic](https://erlangforums.com/u/dominic)\
**Post date:** [December 25, 2025, 7:25am UTC](https://erlangforums.com/t/how-to-merge-multiple-beam-files-into-one-beam/5339/3 "2025-12-25T07:25:12Z")

</div>

thanks, I will use `escript:create/2` to make it 👏 👏 👏
