LinuxCommandLibrary

elixir

Compile and run Elixir code

TLDR

Run an Elixir file

$ elixir [path/to/file]
copy

Evaluate Elixir code by passing it as an argument
$ elixir [[-e|--eval]] "[code]"
copy

SYNOPSIS

elixir [options] [file] [arguments...]
elixir -S script [options] [arguments...]
elixir -v | --version
elixir --help

PARAMETERS

--eval, -e "EXPRESSION"
    Evaluates the given Elixir expression string.

--require, -r FILE
    Requires and loads the given Elixir file before execution.

--compile, -c FILE
    Compiles the given Elixir file without running it.

--no-compile
    Skips compilation of Elixir files during execution.

--no-halt
    Does not halt the Erlang VM after running an Elixir script, keeping the shell open.

--detached
    Starts a detached Erlang VM process, allowing the shell to exit while the VM continues running.

--remsh NODE
    Connects to a remote Erlang/Elixir node to open a remote shell.

--erl "OPTIONS"
    Passes additional options directly to the underlying Erlang VM.

--iex
    Starts the interactive Elixir shell (IEx).

--sname NAME
    Starts the Erlang VM with a short node name for distributed communication (e.g., node@hostname).

--name NAME
    Starts the Erlang VM with a long node name for distributed communication (e.g., node@full.hostname).

--cookie COOKIE
    Sets the Erlang VM cookie for node authentication in distributed systems.

--version, -v
    Prints the Elixir version and exits.

--help
    Prints help information about elixir options and exits.

DESCRIPTION

The elixir command is the primary command-line interface for the Elixir programming language. It serves multiple purposes: running Elixir scripts, compiling Elixir source files, and providing an interactive Elixir shell (IEx). It leverages the Erlang virtual machine (BEAM) for concurrent, fault-tolerant, and distributed applications. Developers use elixir to execute standalone Elixir files, experiment with code in the interactive shell, and sometimes to compile parts of projects. While project management and common tasks are typically handled by the mix build tool, elixir remains the fundamental executable for interacting directly with the Elixir runtime.

CAVEATS

While elixir can compile and run Elixir files, for managing Elixir projects (e.g., creating new projects, managing dependencies, running tests, compiling an entire application), the mix build tool is the standard and recommended approach. elixir is best suited for executing single scripts, short code snippets, or for direct interaction via the IEx shell, especially when not within a mix project context.

RUNNING SCRIPTS VS. INTERACTIVE SHELL

When invoked with a file argument (e.g., elixir my_script.exs), elixir compiles and executes the script. If no file is provided and no specific action like --eval is given, elixir typically starts the interactive shell (IEx) if --iex is implicit or explicitly provided. This provides a convenient environment for trying out Elixir code.

ERLANG VM OPTIONS

Because Elixir runs on the Erlang VM, many Erlang runtime options can be passed to elixir via the --erl "OPTIONS" flag or directly if they are common and recognized by both. This allows fine-grained control over the VM's behavior, such as memory management, process limits, and distributed networking.

HISTORY

Elixir was created by José Valim in 2011, leveraging the Erlang VM to build a modern, productive language with a syntax inspired by Ruby, while inheriting Erlang's capabilities for concurrency, fault tolerance, and distributed systems. The elixir command-line tool has been central to the language's development and usage from its inception, providing the core interface for developers to compile, run, and interact with Elixir code. Its evolution has mirrored the language's growth, with continuous improvements to compilation speed, runtime performance, and the interactive experience.

SEE ALSO

iex(1): The interactive Elixir shell, often started directly or via elixir --iex., mix(1): The build tool for Elixir, used for project management, compilation, testing, and more., erl(1): The Erlang runtime system command, which elixir uses internally to run on the BEAM.

Copied to clipboard