Rebar3 builds

Contents
New project
Project layout
Compile
Run it

New project

Rebar3 is the standard build tool. The new command scaffolds a project from a template: app for a library, escript for a command line tool.

Answer the prompts and the skeleton appears in a folder with your project name.

rebar3 new app myapp

==> Writing myapp/src/myapp_app.erl

==> Writing myapp/src/myapp_sup.erl

==> Writing myapp/rebar.config

Project layout

Source lives in src, tests in test, and build products in _build. The rebar.config file holds the project settings and dependencies.

The scaffold also writes an OTP application skeleton with a supervisor, which lessons 35 and 36 explain.

myapp/

rebar.config

src/myapp_app.erl

src/myapp_sup.erl

test/

_build/

Compile

The compile task builds every module in src and leaves beam files under _build. Rebar3 tracks dependencies and only rebuilds what changed.

Warnings from the compiler appear in the output; treat them as errors until the project is green.

rebar3 compile

==> Compiling myapp

==> App myapp compiled to _build/default/lib/myapp/ebin

Run it

The shell task starts an erl with the project on the code path. Your modules are already loaded and ready to call.

For a one-off run without the shell, use the escript template or erl with the -pa flag pointing at the ebin folder.

rebar3 shell

==> Booted myapp

Eshell V15.2 (abort with ^G)

Next: Testing with EUnit

Article author: Arthur Isaev

Related articles
Erlang
Erlang course: zero to hero in 50 lessons
What is Erlang and where it runs
Install Erlang and check the version
erl: the interactive shell
Your first Erlang script
Variables and single assignment
Numbers
Atoms
Strings and binaries
Truthiness: only false and nil
Conditions: case and if
Recursion replaces loops
Lists
Tuples
Maps
Functions and clauses
Pattern matching
Guards
Records
Exceptions: try and catch
Modules, exports and imports
Funs: anonymous functions
Higher-order functions
Keyword lists
Erlang idioms and clean code
Rebar3 builds
Testing with EUnit
Debugging
Encodings and Unicode
Time and date
JSON and term formats
Processes and message passing
Spawn and links
Monitors and exits
GenServer
Supervisors
OTP applications
Files and IO
Sockets
HTTP clients
io:format and output
Let it crash: error handling
ETS tables
Timers and timeouts
Code loading
Distributed Erlang
Capstone: todo CLI
Capstone: TCP server
Performance
Modern Erlang tour
Hero roadmap: the whole course on one page
Install Erlang on Windows 11
Install Erlang on Ubuntu
Install Erlang on Rocky Linux
Install Erlang on macOS
Install Erlang on FreeBSD
Erlang in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: