Everything you need to go from zero to your first running Elixir code — explained one step at a time
You've heard about Elixir. Maybe someone mentioned it in a podcast. Maybe you read that WhatsApp uses Erlang (Elixir's older cousin) to serve billions of messages. Maybe you're just curious about a language that promises fault-tolerance and concurrency without making your head hurt.
Whatever brought you here — welcome. This article will get you from "I've never written a line of Elixir" to "I have code running on my machine" in about 20 minutes. No previous Elixir knowledge needed. If you've written code in any language before, you'll be fine.
Step 1: Installing Elixir
The cleanest way to install Elixir is through a version manager. This lets you install multiple versions and switch between them easily. The two popular choices in 2026 are asdf and mise.
Using mise (recommended — it's fast and simple)
# Install mise
curl https://mise.run | sh
# Restart your terminal, then install Elixir + Erlang
mise install erlang@27
mise install elixir@1.20
# Tell mise to use these versions
mise use --global erlang@27
mise use --global elixir@1.20
Using asdf (also great)
# Install asdf first from asdf-vm.com, then:
asdf plugin add erlang
asdf plugin add elixir
asdf install erlang 27.0
asdf install elixir 1.20.0
asdf global erlang 27.0
asdf global elixir 1.20.0
Checking the Installation
Open a new terminal and type:
elixir --version
You should see something like:
Erlang/OTP 27 [erts-15.0] [...]
Elixir 1.20.0 (compiled with Erlang/OTP 27)
If you see that — great! Elixir is installed. If you see an error, try closing and reopening your terminal, then running the version check again.
Why do we need Erlang too?
Elixir runs on top of the Erlang virtual machine (called the BEAM). Think of Erlang as the engine and Elixir as the comfortable car body built on top of it. You need both, but you'll mostly interact with Elixir.
Step 2: Meet IEx — Elixir's Interactive Shell
Before we write any files, let's play around in the interactive shell. Type this in your terminal:
iex
You'll see a prompt like:
Erlang/OTP 27 [...]
Interactive Elixir (1.20.0) - press Ctrl+C twice to exit
iex(1)>
The iex(1)> is Elixir asking you to type something. Let's try a few things:
iex(1)> 1 + 1
2
iex(2)> "Hello, World!"
"Hello, World!"
iex(3)> String.upcase("elixir is fun")
"ELIXIR IS FUN"
iex(4)> 100 / 3
33.333333333333336
iex(5)> div(100, 3) # integer division
33
iex(6)> rem(100, 3) # remainder
1
You can type any Elixir expression and see the result immediately. This is called a REPL (Read-Eval-Print Loop) — it Reads what you type, Evaluates it, Prints the result, and Loops back for more.
To exit IEx, press Ctrl+C twice, or type :q and hit Enter.
Step 3: Your First Elixir File
IEx is great for experimenting, but real programs live in files. Let's create one.
Create a file called hello.exs (the .exs extension means "Elixir script"):
# hello.exs
IO.puts("Hello, World!")
IO.puts("My name is Elixir.")
IO.puts("I am #{1 + 1 + 1} years old... just kidding.")
Run it:
elixir hello.exs
Output:
Hello, World!
My name is Elixir.
I am 3 years old... just kidding.
A few things to notice:
-
IO.putsprints a line to the screen (theIOpart means "Input/Output", theputspart means "put string") -
#starts a comment — Elixir ignores everything after it on that line -
#{...}inside a string is string interpolation — it evaluates whatever is inside the braces and puts the result in the string
Step 4: Variables
Variables in Elixir are declared by just using them — no var, let, or const:
# variables.exs
name = "Alice"
age = 28
city = "Nairobi"
IO.puts("#{name} is #{age} years old and lives in #{city}.")
Alice is 28 years old and lives in Nairobi.
One important thing: Elixir variables are lowercase (or snake_case with underscores). Uppercase names mean something else in Elixir (we'll get to that later).
first_name = "Alice" # good
firstName = "Alice" # works, but not idiomatic Elixir
FIRST_NAME = "Alice" # this means something different — don't do this yet
Step 5: Your First Module and Function
Scripts with IO.puts are fine for learning, but real Elixir code lives in modules. Think of a module as a container that groups related functions together.
Create a file called greeter.exs:
# greeter.exs
defmodule Greeter do
# This defines a function called `hello` that takes one argument: `name`
def hello(name) do
"Hello, #{name}! Welcome to Elixir."
end
# A function with a default argument
def greet(name, language \\ "English") do
case language do
"English" -> "Hello, #{name}!"
"Spanish" -> "¡Hola, #{name}!"
"French" -> "Bonjour, #{name}!"
_other -> "Hi, #{name}! (I don't know #{language} yet)"
end
end
end
# Now let's use the module
IO.puts(Greeter.hello("World"))
IO.puts(Greeter.greet("Alice"))
IO.puts(Greeter.greet("Carlos", "Spanish"))
IO.puts(Greeter.greet("Marie", "French"))
IO.puts(Greeter.greet("Zeynep", "Turkish"))
Run it:
elixir greeter.exs
Hello, World! Welcome to Elixir.
Hello, Alice!
¡Hola, Carlos!
Bonjour, Marie!
Hi, Zeynep! (I don't know Turkish yet)
Let's break down what we wrote:
-
defmodule Greeter do ... end— creates a module calledGreeter -
def hello(name) do ... end— defines a function calledhellothat takes one argument -
\\\ "English"— a default value for an argument (if you don't passlanguage, it's"English") -
case language do ... end— a switch/match statement (we'll learn more about this soon) -
_other— a catch-all pattern. The underscore means "I don't care what value this is" -
Greeter.hello("World")— calling a function from a module usesModuleName.function_name(args)
Step 6: Mix — Elixir's Build Tool
For real projects (not just scripts), you use Mix — Elixir's built-in build tool. It creates projects, manages dependencies, runs tests, and more.
Let's create your first Mix project:
mix new my_first_app
You'll see:
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/my_first_app.ex
* creating test
* creating test/test_helper.exs
* creating test/my_first_app_test.exs
Your Mix project was created successfully.
You can use "mix compile" to compile it, "mix test" to run tests.
Navigate into the project:
cd my_first_app
Look at the structure:
my_first_app/
lib/
my_first_app.ex ← your main code goes here
test/
my_first_app_test.exs ← tests go here
mix.exs ← project configuration
Open lib/my_first_app.ex — it already has something in it:
defmodule MyFirstApp do
@moduledoc """
Documentation for `MyFirstApp`.
"""
@doc """
Hello world.
"""
def hello do
:hello
end
end
Run your project interactively:
iex -S mix
This starts IEx with your project loaded. Now you can call your functions:
iex(1)> MyFirstApp.hello()
:hello
:hello is an atom — a special Elixir value that's basically a named constant. We'll learn about atoms in the next article.
A Quick Reference Card
Here's what you learned today, all in one place:
# Running Elixir
# elixir script.exs — run a script
# iex — interactive shell
# iex -S mix — interactive shell with project loaded
# Basic output
IO.puts("text") # prints with newline
IO.inspect(some_value) # prints any value (useful for debugging)
# Variables
name = "Alice"
age = 28
# String interpolation
"Hello, #{name}! You are #{age} years old."
# Basic math
1 + 2 # 3
10 - 3 # 7
4 * 5 # 20
10 / 3 # 3.3333... (float division)
div(10, 3) # 3 (integer division)
rem(10, 3) # 1 (remainder)
# Modules and functions
defmodule MyModule do
def my_function(arg) do
# function body
arg
end
end
MyModule.my_function("hello")
What's Next?
You've installed Elixir, played in IEx, written your first script, created your first module, and set up your first Mix project. That's a real foundation.
In the next article, we'll dive into Elixir's data types — strings, numbers, atoms, lists, tuples, and maps — and start to see how Elixir thinks about data differently from most languages.
For now, experiment! Try modifying the Greeter module to add more languages. Try writing your own function that does some math. Break things — the error messages in Elixir are actually quite helpful.
The best way to learn Elixir is to write Elixir.
Official Resources: The official Elixir Getting Started guide at hexdocs.pm/elixir is the best companion to this article. IEx's built-in help (h IO.puts, h String) documents every standard library function.
Top comments (0)