LinuxCommandLibrary

erl

Start Erlang runtime environment

TLDR

Compile and run sequential Erlang program as a common script and then exit

$ erlc [path/to/file1 path/to/file2 ...] && erl -noshell '[mymodule:myfunction(arguments)], init:stop().'
copy

Connect to a running Erlang node
$ erl -remsh [nodename]@[hostname] -sname [custom_shortname] -hidden -setcookie [cookie_of_remote_node]
copy

Tell the Erlang shell to load modules from a directory
$ erl -pa [path/to/directory_with_beam_files]
copy

SYNOPSIS

erl [-flag value ...] [-s Module Function [Args ...]]
erl [-noshell] [-boot BootFile] [-config ConfigFile] [-eval "Exprs."]
erl [-name NodeName | -sname NodeName] [-setcookie Cookie]

PARAMETERS

-s Module Function [Args ...]
    Calls the specified Function in Module when the system has booted. Optional Args are passed as a list.

-noshell
    Starts the Erlang runtime without an interactive shell. Useful for running batch processes or daemon applications.

-pa Dir
    Adds Dir to the head of the code path. Used to specify directories where Erlang code (.beam files) can be found.

-pz Dir
    Adds Dir to the end of the code path.

-name NodeName
    Starts an Erlang node with a long name (fully qualified domain name). Required for distributed Erlang communication across different hosts.

-sname NodeName
    Starts an Erlang node with a short name. Used for distributed Erlang communication where nodes are on the same host or can resolve names via /etc/hosts.

-setcookie Cookie
    Sets the magic cookie for the node. Nodes must have the same cookie to communicate in a distributed Erlang system.

-boot BootFile
    Specifies an alternative boot script. The boot script defines which applications and modules are loaded at startup.

-config ConfigFile
    Specifies a system configuration file (a .config file). This file contains application environment parameters.

-detached
    Starts the Erlang emulator in detached mode, running as a daemon process in the background. Standard I/O is redirected to /dev/null.

-eval "Exprs."
    Evaluates Erlang expressions before starting the shell or applications. Multiple -eval options are evaluated sequentially.

-extra Args ...
    Passes extra arguments to the Erlang program. These arguments are accessible via init:get_plain_arguments/0.

-run Module Function [Args ...]
    Similar to -s, but it is executed before any initial module specified by the boot script. It also causes the system to terminate if the function returns.

-emu_args Args ...
    Passes arguments directly to the Erlang emulator (VM). These are low-level options affecting VM behavior.

-version
    Prints the Erlang/OTP version string and exits.

-help
    Displays a brief help message with common command-line options.

DESCRIPTION

The erl command is the primary executable for starting the Erlang/OTP runtime system. It provides an interactive shell for development and debugging, or can be used to execute Erlang code and start Erlang applications in a production environment.

Erlang/OTP is a programming language and platform designed for building scalable, soft real-time, distributed, fault-tolerant systems. The erl command is central to this, managing processes, memory, and inter-node communication, forming the backbone for applications requiring high availability and concurrency.

It supports a wide array of command-line options to configure the runtime behavior, code loading paths, network distribution, and system initialization, making it highly flexible for various deployment scenarios.

CAVEATS

The erl command has an exceptionally extensive list of command-line options, many of which are highly specific to internal system behavior, memory management, or debugging. This analysis lists only the most commonly used and important options. For a comprehensive and exhaustive list, users should consult the official Erlang/OTP Reference Manual for erl(1).

Understanding the Erlang/OTP boot process and release handling is crucial for advanced usage of erl in production environments.

INTERACTIVE SHELL

When run without specific instructions to execute code (e.g., without -s or -noshell), erl starts an interactive Erlang shell. This shell provides a powerful environment for experimentation, debugging, and administrative tasks on a running Erlang node. Users can evaluate Erlang expressions, inspect processes, and interact with applications directly.

DISTRIBUTED ERLANG

A key feature of Erlang/OTP is its built-in support for distributed computing. The erl command, with options like -name or -sname and -setcookie, allows Erlang nodes to communicate seamlessly over a network. This enables building applications composed of multiple interconnected nodes, facilitating fault tolerance and scalability by allowing processes to reside on different machines and migrate if necessary.

OTP APPLICATIONS AND RELEASES

While erl can start simple Erlang scripts, its full power is realized when starting OTP Applications or Releases. An OTP application is a standard component structure in Erlang, and a Release is a self-contained deployable unit of one or more OTP applications. The erl command is used by release boot scripts to initialize complex Erlang systems, ensuring all necessary applications are started in the correct order and configuration.

HISTORY

Erlang was developed by Ericsson in the mid-1980s, with its first version released in 1986. It was specifically designed for building highly concurrent, distributed, fault-tolerant, and soft real-time applications, initially for the telecommunications industry. The Erlang runtime system (erl) was a core component from its inception.

The Erlang/OTP (Open Telecom Platform) framework, which bundles the Erlang language with a rich set of libraries and design principles, was open-sourced in 1998, making erl and the entire platform accessible to a wider audience. Since then, Erlang has found widespread use in various industries beyond telecom, including messaging, gaming, and financial services, leveraging its unique properties for scalable backend systems.

SEE ALSO

escript(1), epmd(1), erl_call(1), man(1), init(3)

Copied to clipboard