Elixir’s Interactive Shell (IEx)

Elixir ships with an interactive shell called IEx (Interactive Elixir). Think of it as a calculator for the language: you type an expression, press Enter, and Elixir shows you the result. It is the single most useful tool for learning the language, and we will use it for most of the examples in this chapter.

Start IEx from your command line:

$ iex
Erlang/OTP 28 [erts-16.2.2] [source] [64-bit] [...]

Interactive Elixir (1.20.0-rc.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> (1)
1 This is the IEx prompt. The number in parentheses counts the expressions you have entered so far.

Try a first expression. IEx prints the result right back at you:

iex(1)> 1 + 1
2
iex(2)> "Hello, " <> "World!"
"Hello, World!"
To leave IEx, press CTRL-C twice, or CTRL-\ once.
Two shortcuts you will use every day
  • Tab completion. Start typing String. and hit TAB to see all functions in the String module.

  • History. Press the up arrow to scroll through expressions you ran before, just like in bash or zsh.

Do you like video tutorials? Have a look at the "IEx Basics in 55 Seconds" video in our @elixir-phoenix-ash YouTube Channel.