Getting Started
Install Elixir, explore the IEx interactive shell, and create your first Mix project. A beginner-friendly guide with code examples comparing Elixir to Python and JavaScript.
What Is Elixir?
Elixir is a dynamic, functional programming language designed for building scalable and maintainable applications. Created by Jose Valim in 2011, it runs on the Erlang Virtual Machine (BEAM), the same platform that powers telephone switches, messaging systems, and other infrastructure that demands high availability.
Why the BEAM Matters
Elixir adds modern language features on top of the BEAM: a Ruby-like syntax, powerful metaprogramming through macros, first-class documentation, and a thriving ecosystem of libraries published on hex.pm.
Why Learn Elixir?
- Concurrency without complexity. The BEAM spawns lightweight processes (not OS threads) that communicate through message passing. You can run millions of them simultaneously.
- Fault tolerance by design. Supervisors monitor processes and restart them when they crash, following the “let it crash” philosophy.
- Productivity. Pattern matching, the pipe operator, and a consistent standard library make code concise and readable.
- Growing ecosystem. Phoenix (web framework), LiveView (real-time UIs), Nx (numerical computing), and Nerves (embedded systems) are just a few of the major projects in the ecosystem.
Installing Elixir
The recommended way to install Elixir depends on your operating system.
macOS (using Homebrew):
brew install elixir
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install elixir
Windows (using the official installer):
Download the installer from elixir-lang.org/install and follow the prompts.
Using asdf version manager (recommended for managing multiple versions):
asdf plugin add erlang
asdf plugin add elixir
asdf install erlang 27.0
asdf install elixir 1.17.2-otp-27
asdf global erlang 27.0
asdf global elixir 1.17.2-otp-27
After installation, verify everything is working:
elixir --version
You should see output similar to:
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]
Elixir 1.17.2 (compiled with Erlang/OTP 27)
Exploring IEx
IEx (Interactive Elixir) is Elixir’s REPL (Read-Eval-Print Loop). Start it by running iex in your terminal:
iex> 1 + 1
2
iex> "hello" <> " " <> "world"
"hello world"
iex> String.upcase("elixir")
"ELIXIR"
IEx is an essential tool you will use constantly. A few helpful commands inside IEx:
iex> h String.upcase
Returns a string where all characters are converted to uppercase...
iex> i "hello"
Term
"hello"
Data type
BitString
Byte size
5
Description
This is a string: a UTF-8 encoded binary...
The h helper displays documentation for any module or function. The i helper inspects a value, showing its type and metadata. These two commands alone make IEx a powerful learning environment.
Ctrl+C twice, or type System.halt.Comparing the REPL Experience
If you are coming from Python or JavaScript, the IEx experience will feel familiar but has some Elixir-specific features built in.
# Python REPL
>>> help(str.upper)
>>> type("hello")
<class 'str'>
>>> "hello".upper()
'HELLO'
// Node.js REPL
> typeof "hello"
'string'
> "hello".toUpperCase()
'HELLO'
# Elixir IEx
iex> h String.upcase
iex> i "hello"
iex> String.upcase("hello")
"ELIXIR"
Notice that in Elixir, functions are called on modules (String.upcase("hello")) rather than on the data itself ("hello".upper()). This is a characteristic of functional programming: data and functions are separate.
Creating Your First Mix Project
Mix is Elixir’s build tool. It creates projects, compiles code, runs tests, manages dependencies, and much more. Think of it as a combination of npm, pip, cargo, and make rolled into one.
Create a new project:
mix new hello
This generates a project directory:
hello/
lib/
hello.ex # Your main module
test/
hello_test.exs # Tests
test_helper.exs # Test configuration
mix.exs # Project configuration (like package.json or Cargo.toml)
README.md
.formatter.exs # Code formatter configuration
.gitignore
Let’s look at the generated lib/hello.ex:
defmodule Hello do
@moduledoc """
Documentation for `Hello`.
"""
@doc """
Hello world.
## Examples
iex> Hello.hello()
:world
"""
def hello do
:world
end
end
This defines a module named Hello with a single function hello/0 that returns the atom :world. The @moduledoc and @doc attributes are documentation that IEx and documentation generators can read.
Running Your Code
There are several ways to execute Elixir code.
Run a script directly:
Create a file called hello.exs (note the .exs extension for scripts):
IO.puts("Hello, world!")
Run it:
elixir hello.exs
Run inside your Mix project:
cd hello
iex -S mix
The -S mix flag tells IEx to start with your project loaded:
iex> Hello.hello()
:world
iex> IO.puts("Hello from my first project!")
Hello from my first project!
:ok
Run tests:
mix test
Compiling 1 file (.ex)
Generated hello app
..
Finished in 0.03 seconds (0.03s async, 0.00s sync)
1 test, 0 failures
.ex vs .exs Files
.ex files are compiled into BEAM bytecode and are used for production code. .exs files are scripts that are interpreted at runtime, typically used for configuration, tests, and one-off scripts. Both contain valid Elixir code; the difference is in how they are executed.Modifying the Project
Open lib/hello.ex and add a new function:
defmodule Hello do
@moduledoc """
Documentation for `Hello`.
"""
@doc """
Greets the given name.
## Examples
iex> Hello.greet("Elixir")
"Hello, Elixir!"
"""
def greet(name) do
"Hello, #{name}!"
end
end
The #{} syntax is string interpolation – it evaluates the expression inside the braces and inserts the result into the string.
Now test it:
iex> Hello.greet("Elixir")
"Hello, Elixir!"
iex> Hello.greet("World")
"Hello, World!"
Create Your Own Mix Project
- Run
mix new greeterto create a new project. - In
lib/greeter.ex, write a functiongreet/1that takes a name and returns"Welcome, <name>! Let's learn Elixir together.". - Add a function
greet/0(no arguments) that returns"Welcome, stranger! Let's learn Elixir together.". - Start
iex -S mixand call both functions. - Run
mix testto make sure the generated tests still pass.
Bonus: Add @doc attributes to your functions and use h Greeter.greet in IEx to view them.
What’s Next
You now have Elixir installed, know how to use IEx for exploration, and can create and run Mix projects. In the next lesson, you will learn about Elixir’s basic data types – the building blocks every program is made of.
Related Lessons
Key Takeaways
- Elixir runs on the Erlang VM (BEAM), giving it access to decades of battle-tested concurrency and fault-tolerance infrastructure
- IEx is your interactive playground for experimenting with Elixir code
- Mix is the build tool that manages projects, dependencies, and tasks
- Every Elixir project follows a conventional directory structure created by `mix new`