Initial Setup
Want to start programming in Elixir? This initial setup guide gets Elixir installed and working on your system in minutes. By the end, you’ll have Elixir running and will execute your first program interactively.
This tutorial provides 0-5% coverage - just enough to get Elixir working on your machine. For deeper learning, continue to Quick Start (5-30% coverage).
Prerequisites
Before installing Elixir, you need:
- A computer running Windows, macOS, or Linux
- Administrator/sudo access for installation
- A terminal/command prompt
- A text editor (VS Code, IntelliJ IDEA, Emacs, Vim, or any editor)
- Basic command-line navigation skills
- Erlang/OTP (we’ll install this first)
No prior Erlang or functional programming experience required - this guide starts from zero.
Learning Objectives
By the end of this tutorial, you will be able to:
- Install Erlang/OTP (the BEAM virtual machine)
- Install Elixir on your operating system
- Access IEx (Interactive Elixir shell)
- Execute Elixir code interactively
- Create and run your first Elixir project with Mix
Erlang/OTP Installation
Elixir runs on the Erlang VM (BEAM), so we need Erlang first.
Windows Erlang/OTP Installation
Step 1: Download Erlang/OTP Installer
- Visit https://www.erlang.org/downloads
- Download Windows installer for OTP 26 or later (e.g.,
otp_win64_26.2.exe)
Alternative: Use Chocolatey
If you have Chocolatey installed:
choco install erlangStep 2: Run Installer
- Double-click downloaded
.exefile - Follow installation wizard:
- Accept license agreement
- Keep default installation path (
C:\Program Files\Erlang OTP) - Click Install
- Click Finish
Step 3: Verify Installation
Open new Command Prompt or PowerShell:
erl -versionExpected output:
Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 14.2Troubleshooting Windows:
- If
erlnot found, addC:\Program Files\Erlang OTP\binto PATH - Restart Command Prompt after installation
macOS Erlang/OTP Installation
Step 1: Install via Homebrew
brew install erlangHomebrew downloads and installs Erlang/OTP automatically.
Step 2: Verify Installation
erl -versionExpected output:
Erlang (SMP,ASYNC_THREADS,JIT) (BEAM) emulator version 14.2Alternative: asdf Version Manager (Recommended for developers)
asdf allows managing multiple Erlang and Elixir versions:
brew install asdf
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zshrc
source ~/.zshrc
asdf plugin add erlang
asdf install erlang 26.2
asdf global erlang 26.2Troubleshooting macOS:
- If Homebrew installation fails, run
brew updatefirst - For Apple Silicon Macs, Homebrew installs ARM-optimized builds automatically
Linux Erlang/OTP Installation
Ubuntu/Debian:
sudo apt update
sudo apt install build-essential autoconf m4 libncurses5-dev \
libwxgtk3.0-gtk3-dev libwxgtk-webview3.0-gtk3-dev libgl1-mesa-dev \
libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop \
libxml2-utils libncurses-dev openjdk-11-jdk
wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb
sudo dpkg -i erlang-solutions_2.0_all.deb
sudo apt update
sudo apt install esl-erlangFedora/RHEL/CentOS:
sudo dnf install erlangArch Linux:
sudo pacman -S erlangAlternative: asdf Version Manager (Recommended)
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
source ~/.bashrc
asdf plugin add erlang
sudo apt install build-essential autoconf m4 libncurses5-dev \
libwxgtk3.0-gtk3-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev \
libssh-dev unixodbc-dev xsltproc fop libxml2-utils
asdf install erlang 26.2
asdf global erlang 26.2Verify Installation:
erl -versionExpected output:
Erlang (SMP,ASYNC_THREADS,JIT) (BEAM) emulator version 14.2Troubleshooting Linux:
- If compilation fails, ensure all build dependencies installed
- Check disk space (Erlang compilation requires ~2GB temporary space)
Elixir Installation
With Erlang installed, now install Elixir.
Windows Elixir Installation
Step 1: Download Elixir Installer
Visit https://elixir-lang.org/install.html#windows
Use the Web Installer (recommended) or download precompiled zip.
Alternative: Chocolatey
choco install elixirStep 2: Verify Installation
Open new Command Prompt:
elixir --versionExpected output:
Erlang/OTP 26 [erts-14.2] [64-bit] [smp:8:8] [async-threads:1] [jit]
Elixir 1.16.0 (compiled with Erlang/OTP 26)Troubleshooting Windows:
- Ensure both Erlang and Elixir bin directories are in PATH
- Restart Command Prompt after installation
macOS Elixir Installation
Step 1: Install via Homebrew
brew install elixirAlternative: asdf (if you installed Erlang via asdf)
asdf plugin add elixir
asdf install elixir 1.16.0-otp-26
asdf global elixir 1.16.0-otp-26Step 2: Verify Installation
elixir --versionExpected output:
Erlang/OTP 26 [erts-14.2] [64-bit] [smp:10:10] [async-threads:1] [jit]
Elixir 1.16.0 (compiled with Erlang/OTP 26)Troubleshooting macOS:
- If
elixirnot found, ensure Homebrew bin directory in PATH - Run
brew doctorto diagnose Homebrew issues
Linux Elixir Installation
Ubuntu/Debian (using Erlang Solutions repository):
sudo apt update
sudo apt install elixirFedora/RHEL/CentOS:
sudo dnf install elixirArch Linux:
sudo pacman -S elixirAlternative: asdf (Recommended)
asdf plugin add elixir
asdf install elixir 1.16.0-otp-26
asdf global elixir 1.16.0-otp-26Verify Installation:
elixir --versionExpected output:
Erlang/OTP 26 [erts-14.2] [64-bit] [smp:8:8] [async-threads:1] [jit]
Elixir 1.16.0 (compiled with Erlang/OTP 26)Troubleshooting Linux:
- Ensure Elixir compiled for correct OTP version
- If version mismatch, use asdf to manage compatible versions
Your First IEx Session
IEx (Interactive Elixir) is Elixir’s REPL for interactive programming.
Launch IEx
Open terminal and run:
iexYou’ll see the Elixir prompt:
Erlang/OTP 26 [erts-14.2] [64-bit] [smp:8:8] [async-threads:1] [jit]
Interactive Elixir (1.16.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>The iex(1)> prompt means IEx is ready for input (number increments with each command).
Execute Your First Elixir Code
Print “Hello, World!”:
iex(1)> IO.puts("Hello, World!")Output:
Hello, World!
:okExplanation:
IO.puts- Function to print with newline"Hello, World!"- String argument:ok- Return value (atom indicating success)
Basic Arithmetic:
iex(2)> 2 + 3
5
iex(3)> 10 * 5
50
iex(4)> 20 / 4
5.0Elixir uses standard infix operators for arithmetic.
String Concatenation:
iex(5)> "Hello, " <> "Elixir!"
"Hello, Elixir!"Define a Variable:
iex(6)> x = 42
42
iex(7)> x
42
iex(8)> message = "Hello, Elixir!"
"Hello, Elixir!"
iex(9)> message
"Hello, Elixir!"Pattern Matching:
iex(10)> {a, b, c} = {1, 2, 3}
{1, 2, 3}
iex(11)> a
1
iex(12)> b
2Define a Function:
iex(13)> greet = fn name -> "Hello, #{name}!" end
#Function<44.65746770/1 in :erl_eval.expr/5>
iex(14)> greet.("Alice")
"Hello, Alice!"Call Standard Library Functions:
iex(15)> String.upcase("elixir")
"ELIXIR"
iex(16)> String.length("Hello")
5
iex(17)> Enum.map([1, 2, 3], fn x -> x * 2 end)
[2, 4, 6]IEx Helper Functions
Help:
iex(18)> h()Shows IEx help overview.
Function Documentation:
iex(19)> h String.upcaseShows documentation for String.upcase.
Module Information:
iex(20)> i "hello"Shows information about the value (type, protocols, etc.).
Exit IEx:
Press Ctrl+C twice, or:
iex(21)> System.halt()Create Your First Elixir Project
Mix is Elixir’s build tool and project manager.
Verify Mix Installation
Mix installs with Elixir:
mix --versionExpected output:
Mix 1.16.0 (compiled with Erlang/OTP 26)Create a New Project
mix new hello_elixirOutput:
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/hello_elixir.ex
* creating test
* creating test/test_helper.exs
* creating test/hello_elixir_test.exs
Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:
cd hello_elixir
mix test
Run "mix help" for more commands.This creates hello_elixir/ directory with project structure:
hello_elixir/
├── mix.exs # Project configuration
├── README.md # Project documentation
├── .formatter.exs # Code formatter configuration
├── .gitignore # Git ignore rules
├── lib/
│ └── hello_elixir.ex # Main source file
└── test/
├── test_helper.exs
└── hello_elixir_test.exsExplore Project Structure
Navigate into project:
cd hello_elixirView mix.exs:
cat mix.exsContents:
defmodule HelloElixir.MixProject do
use Mix.Project
def project do
[
app: :hello_elixir,
version: "0.1.0",
elixir: "~> 1.16",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[]
end
endView lib/hello_elixir.ex:
cat lib/hello_elixir.exContents:
defmodule HelloElixir do
@moduledoc """
Documentation for `HelloElixir`.
"""
@doc """
Hello world.
## Examples
iex> HelloElixir.hello()
:world
"""
def hello do
:world
end
endRun Tests
Elixir projects include tests by default:
mix testOutput:
Compiling 1 file (.ex)
Generated hello_elixir app
..
Finished in 0.03 seconds (0.00s async, 0.03s sync)
1 doctest, 1 test, 0 failures
Randomized with seed 123456Tests pass - your project works!
Modify the Module
Edit lib/hello_elixir.ex:
defmodule HelloElixir do
@moduledoc """
Greetings module for learning Elixir.
"""
@doc """
Greet someone by name.
## Examples
iex> HelloElixir.greet("Alice")
"Hello, Alice! Welcome to Elixir."
"""
def greet(name) do
"Hello, #{name}! Welcome to Elixir."
end
@doc """
Add two numbers.
## Examples
iex> HelloElixir.add(2, 3)
5
"""
def add(a, b) do
a + b
end
endStart Project IEx
Launch IEx with project loaded:
iex -S mixOutput:
Erlang/OTP 26 [erts-14.2] [64-bit] [smp:8:8] [async-threads:1] [jit]
Compiling 1 file (.ex)
Generated hello_elixir app
Interactive Elixir (1.16.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>Now test your functions:
iex(1)> HelloElixir.greet("Bob")
"Hello, Bob! Welcome to Elixir."
iex(2)> HelloElixir.add(10, 32)
42Why iex -S mix? It compiles and loads your project, enabling interactive testing.
Compile the Project
Compile without starting IEx:
mix compileOutput:
Compiling 1 file (.ex)
Generated hello_elixir appCompiled files go to _build/ directory.
Run Specific Function
Execute a function from command line:
mix run -e 'IO.puts(HelloElixir.greet("World"))'Output:
Hello, World! Welcome to Elixir.Format Code
Elixir includes automatic code formatter:
mix formatThis formats all .ex and .exs files according to Elixir style guide.
Understanding Elixir’s Interactive Development
Elixir emphasizes fast feedback through interactive development.
IEx Workflow
Typical Elixir development:
- Start IEx with
iex -S mix - Write or modify code in source files
- Recompile in IEx:
recompile() - Test functions interactively
- Iterate based on results
This tight feedback loop enables rapid experimentation.
Useful IEx Commands
Recompile Project:
iex(1)> recompile()Recompiles changed files without restarting IEx.
Auto-complete:
Type module or function name and press Tab:
iex(2)> String.[TAB]Shows available functions in String module.
Previous Expression:
iex(3)> 2 + 3
5
iex(4)> v(3)
5v(3) retrieves result from line 3.
Clear Screen:
iex(5)> clear()Or press Ctrl+L.
Development Environment Setup
Several editors provide excellent Elixir support.
VS Code with ElixirLS
Step 1: Install VS Code
Download from https://code.visualstudio.com/
Step 2: Install ElixirLS Extension
- Open VS Code
- Go to Extensions (Ctrl+Shift+X or Cmd+Shift+X)
- Search for “ElixirLS”
- Click Install
Step 3: Open Elixir Project
- File → Open Folder → Select
hello_elixirdirectory - ElixirLS automatically compiles project
- Get autocomplete, go-to-definition, and inline documentation
ElixirLS provides debugging, mix task integration, and formatter integration.
IntelliJ IDEA with Elixir Plugin
Step 1: Install IntelliJ IDEA
Download Community Edition from https://www.jetbrains.com/idea/download/
Step 2: Install Elixir Plugin
- Open IntelliJ IDEA
- File → Settings → Plugins
- Search for “Elixir”
- Install and restart IDE
Step 3: Import Project
- File → Open → Select
hello_elixirdirectory - Configure Elixir SDK (point to Elixir installation)
- Project compiles automatically
Provides refactoring, debugging, and mix integration.
Emacs with Alchemist (Advanced)
Emacs users often use Alchemist mode:
- Install Emacs
- Install Alchemist: Add to
.emacsorinit.el:
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)Then M-x package-install RET alchemist RET
- Open Elixir file and start IEx:
M-x alchemist-iex-project-run
Verify Your Setup Works
Let’s confirm everything is functioning correctly.
Test 1: Erlang Installed
erl -versionShould show Erlang version 23 or later.
Test 2: Elixir Installed
elixir --versionShould show Elixir 1.14 or later with matching OTP version.
Test 3: Mix Works
mix --versionShould show Mix version matching Elixir version.
Test 4: IEx Access
iexShould open IEx. Try IO.puts("Test"), should print “Test”. Exit with Ctrl+C twice.
Test 5: Project Creation and Testing
mix new test_project
cd test_project
mix testTests should pass.
All tests passed? Your Elixir setup is complete!
Summary
What you’ve accomplished:
- Installed Erlang/OTP (BEAM virtual machine)
- Installed Elixir on your operating system
- Accessed and used IEx (Interactive Elixir shell)
- Executed Elixir code interactively
- Created and ran your first Mix project
- Understood interactive development workflow
- Ran tests with Mix test framework
Key commands learned:
erl -version- Check Erlang installationelixir --version- Check Elixir versionmix --version- Check Mix versioniex- Start interactive shellmix new <name>- Create new projectmix compile- Compile projectmix test- Run testsmix format- Format codeiex -S mix- Start IEx with project loaded
Skills gained:
- Erlang/OTP and Elixir environment setup
- IEx interactive shell usage
- Mix project management basics
- Basic Elixir syntax understanding
- Project structure navigation
Next Steps
Ready to learn Elixir syntax and concepts?
- Quick Start (5-30% coverage) - Touch all core Elixir concepts in a fast-paced tour
Want comprehensive fundamentals?
Prefer code-first learning?
- By-Example Tutorial - Learn through heavily annotated examples
Want to understand Elixir’s design philosophy?
- Overview - Why Elixir exists and when to use it
Troubleshooting Common Issues
“erl: command not found”
Problem: Erlang not installed or not in PATH.
Solution:
- Install Erlang following platform-specific instructions above
- Verify PATH includes Erlang bin directory
- Restart terminal after installation
“elixir: command not found”
Problem: Elixir not in PATH or not installed.
Solution:
- Install Elixir following platform-specific instructions
- Check PATH includes Elixir installation directory
- Restart terminal after installation
OTP version mismatch
Problem: Elixir compiled with different OTP version than installed Erlang.
Solution:
- Use asdf to manage both Erlang and Elixir with compatible versions
- Ensure Elixir 1.16 uses OTP 24-27
- Reinstall Elixir to match installed OTP version
“Mix could not compile”
Problem: Project compilation fails.
Solution:
- Delete
_build/directory:rm -rf _build - Delete
deps/directory:rm -rf deps - Recompile:
mix deps.get && mix compile - Check syntax errors in source files
IEx crashes on startup
Problem: IEx exits immediately or crashes.
Solution:
- Check Erlang installation:
erlshould start Erlang shell - Verify Elixir version compatibility with OTP
- Check terminal supports UTF-8 encoding
- Try starting with verbose output:
iex --verbose
Windows: “The program can’t start because erl.exe is missing”
Problem: Erlang not properly installed on Windows.
Solution:
- Reinstall Erlang from official website
- Ensure installation completed without errors
- Add
C:\Program Files\Erlang OTP\binto system PATH - Restart computer after installation
Further Resources
Official Documentation:
- Elixir Official Site - Official Elixir website
- Elixir Documentation - Complete API documentation
- Mix Documentation - Mix build tool guide
- IEx Documentation - Interactive shell reference
Interactive Learning:
- Elixir School - Free Elixir tutorial
- Exercism Elixir Track - Practice problems with mentorship
- Koans - Learn through failing tests
Books:
- Programming Elixir - Dave Thomas, comprehensive introduction
- Elixir in Action - Saša Jurić, practical approach
- The Little Elixir & OTP Guidebook - Benjamin Tan, OTP focus
Community:
- Elixir Forum - Official discussion forum
- Elixir Slack - Community chat
- /r/elixir - Reddit community
- ElixirConf - Annual conference