LinuxCommandLibrary

iex

Start an Elixir interactive shell

TLDR

Start an interactive session

$ iex
copy

Start a session that remembers history
$ iex --erl "-kernel shell_history enabled"
copy

Start and load Mix project files
$ iex -S mix
copy

SYNOPSIS

iex [options] [files]

PARAMETERS

--help
    Display help message and exit

--version
    Print IEx and Elixir version

-v
    Verbose mode, print compilation info

-e EXPR
    Evaluate EXPR then exit

-S SCRIPT
    Start IEx and run SCRIPT (e.g., mix)

--no-halt
    Do not halt VM after execution

--erl "OPTS"
    Pass Erlang VM options

-r FILE
    Require FILE before starting

--name NAME
    Set long node name (distributed)

--cookie COOKIE
    Set distribution cookie

--remsh NODE
    Connect remote shell to NODE

DESCRIPTION

IEx (Interactive Expression) is the standard interactive shell for the Elixir programming language. It provides a REPL (Read-Eval-Print Loop) environment where developers can execute Elixir code interactively, inspect data structures, explore modules, and prototype applications.

Key features include syntax highlighting, pretty-printing of complex data (like structs and maps), code reloading, history navigation with arrow keys, and tab completion. IEx integrates seamlessly with Elixir's build tool Mix, allowing commands like iex -S mix to load projects directly.

It supports helpers like h/1 for documentation, i/1 for inspecting terms, r/1 for recompiling modules, and t/1 for typespecs. IEx runs on the Erlang VM (BEAM), inheriting its concurrency model, fault-tolerance, and distribution capabilities. Ideal for learning Elixir, debugging, and live inspections in production (with caution).

Unlike basic shells, IEx emphasizes productivity with features like autocomplete, exception stacktraces with source locations, and remote shells for distributed nodes.

CAVEATS

Requires Elixir installed; inherits Erlang VM limits (e.g., max ports). Not for production without restrictions. Interactive mode may consume resources on long sessions.
Remote shells need same cookie and network access.

COMMON HELPERS

h/1: Module docs
i/1: Inspect term
r/Module: Recompile
v/1: Variable history
t/1: Typespec

EXAMPLE USAGE

iex -S mix
Interactive prompt: iex(1)>
Run: IO.puts "Hello"
Quit: System.halt() or Ctrl+C twice

HISTORY

Developed by José Valim as part of Elixir (first release 2012). IEx introduced in Elixir 0.10 (2012), evolved with features like pretty-printing (1.0, 2014), dot syntax (1.5, 2017). Core to Elixir's ecosystem, now at Elixir 1.15+.

SEE ALSO

elixir(1), erl(1), escript(1), mix(1)

Copied to clipboard