Installing Elixir and Mix
Before writing any Elixir code, you need two things installed: the Erlang/OTP runtime, since Elixir compiles down to BEAM bytecode that Erlang's virtual machine executes, and the Elixir compiler and standard library itself. Most modern installation methods handle both automatically. Once installed, you get two essential command-line tools: elixir, which compiles and runs .ex or .exs scripts directly, and mix, Elixir's built-in build tool for creating and managing projects.
Cricket analogy: Installing Erlang before Elixir is like a cricket academy insisting a batter first master the basics of the forward defensive before being handed a modern power-hitting bat, the fundamentals (BEAM) have to be in place before the higher-level tool (Elixir) works.
Installing Elixir on Your System
On macOS, the fastest path is Homebrew: brew install elixir installs both Erlang and Elixir. On Debian/Ubuntu Linux, apt install elixir works, though it may lag behind the latest release. On Windows, the official .exe installer from elixir-lang.org bundles Erlang automatically. For serious project work, most experienced Elixir developers instead recommend a version manager like asdf, which lets you install specific Erlang and Elixir versions and pin them per project using a .tool-versions file, avoiding 'works on my machine' mismatches across a team.
Cricket analogy: Using asdf to pin exact Elixir/Erlang versions per project is like a franchise locking in the exact bat willow grade and weight a player used during a record century, ensuring the same setup is reproduced for every future net session.
After installation, running elixir -v prints both the Elixir and the underlying Erlang/OTP version, which is useful for confirming compatibility, since Elixir versions have minimum supported Erlang/OTP versions. More importantly, typing iex at the terminal launches Interactive Elixir, a REPL where you can evaluate expressions, define modules, and inspect data on the fly; iex is the primary tool most Elixir developers use to explore the standard library and debug small snippets before putting them into a project file.
Cricket analogy: Checking elixir -v before coding is like a bowler checking the pitch report before a match, confirming conditions match what your strategy assumes before you commit to a plan.
# macOS (Homebrew)
brew install elixir
# Ubuntu/Debian
sudo apt update && sudo apt install elixir
# Using asdf version manager (recommended for teams)
asdf plugin add erlang
asdf plugin add elixir
asdf install erlang 26.2.1
asdf install elixir 1.16.0-otp-26
asdf local erlang 26.2.1
asdf local elixir 1.16.0-otp-26
# Verify installation
elixir -v
# Erlang/OTP 26 [erts-14.2.1] [64-bit]
# Elixir 1.16.0 (compiled with Erlang/OTP 26)
# Launch the interactive shell
iex
iex> 1 + 1
2asdf reads a .tool-versions file in your project root to automatically switch to the correct Elixir and Erlang versions whenever you cd into that directory. Commit .tool-versions to version control so every teammate, and your CI pipeline, builds with the exact same runtime.
Mix: Elixir's Build Tool
Mix is the command-line build tool bundled with every Elixir installation, and it plays a role similar to npm plus webpack in the JavaScript world, or Cargo in Rust. Running mix new my_app scaffolds a new project with a standard directory layout: lib/ for source code, test/ for ExUnit tests, and a mix.exs file that declares the project's dependencies, version, and configuration. Mix also manages dependencies pulled from Hex, Elixir's official package repository, and drives common workflows through tasks like mix deps.get, mix compile, mix test, and mix run.
Cricket analogy: Mix scaffolding a new project is like a franchise's academy handing a promising young player a standardized training kit on day one, bat, pads, kit bag, so every recruit starts from the same organized baseline instead of assembling gear ad hoc.
A freshly generated Mix project follows a predictable layout: lib/my_app.ex holds the main module, test/my_app_test.exs holds its corresponding ExUnit test, and mix.exs defines metadata like the app name, Elixir version requirement, and a deps/0 function listing external packages. Running mix deps.get downloads any listed dependencies into a deps/ folder and records exact resolved versions in mix.lock, similar to how package-lock.json pins versions in Node.js, ensuring every developer and every deployment installs identical dependency versions.
Cricket analogy: mix.lock pinning exact dependency versions is like a team's final playing XI being locked in and submitted to the umpire before the toss, no substitutions once the match officially starts.
mix new my_app
cd my_app
# Generated structure:
# my_app/
# lib/my_app.ex
# test/my_app_test.exs
# test/test_helper.exs
# mix.exs
# .formatter.exs
# .gitignore# mix.exs
defmodule MyApp.MixProject do
use Mix.Project
def project do
[
app: :my_app,
version: "0.1.0",
elixir: "~> 1.16",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
defp deps do
[
{:jason, "~> 1.4"}
]
end
endAdding a package to the deps/0 list in mix.exs does not install it. You must run mix deps.get afterward to fetch it from Hex; forgetting this step is a common source of ** (Mix) Could not compile dependency errors when you then try to run mix compile or mix test.
- Elixir requires the Erlang/OTP runtime; installers usually bundle both together.
- Use a version manager like asdf with a .tool-versions file to pin exact versions per project.
- elixir -v verifies your installed Elixir and Erlang/OTP versions.
- iex launches Interactive Elixir, the REPL used for exploring code and debugging.
- mix new scaffolds a standard project layout with lib/, test/, and mix.exs.
- mix.exs declares project metadata and dependencies; mix.lock pins resolved versions.
- Always run mix deps.get after editing dependencies in mix.exs, before compiling or testing.
Practice what you learned
1. What must be installed alongside Elixir for it to run?
2. Which command launches Elixir's interactive REPL?
3. What file does mix new generate to declare a project's dependencies?
4. What is the purpose of mix.lock?
5. What must you run after adding a new dependency to mix.exs before it's usable?
Was this page helpful?
You May Also Like
What Is Elixir?
An introduction to Elixir, a functional, concurrent programming language built on the Erlang VM for building scalable and fault-tolerant applications.
Your First Elixir Program
Write, run, and understand your first Elixir program, from a standalone script to a proper Mix module with functions and a test.
Elixir Data Types
A tour of Elixir's built-in data types, integers, floats, atoms, booleans, strings, lists, tuples, and maps, and how immutability shapes the way they behave.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics