0Pricing
Elixir & Phoenix: Scalable Backend Development · Lesson

Building Releases with Mix Release

Create self-contained and ready-to-deploy releases of your Elixir application using `mix release`.

Building Releases with Mix Release is a free Elixir & Phoenix: Scalable Backend Development lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Elixir & Phoenix: Scalable Backend Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome to Elixir Releases

When you develop an Elixir application, you often run it with mix run --no-halt. This is great for development, but not ideal for production.

For deployment, we need a self-contained package that can run independently, without needing the Mix build tool or even Elixir's source code on the target machine. This is where releases come in!

Why `mix run` Isn't Enough

Running an application with mix run has a few drawbacks for production:

  • It requires the full Mix build tool and your project's source code.
  • It uses the development environment configuration by default.
  • Startup can be slower as it needs to compile and load dependencies.
  • It lacks proper daemonization features for background processes.

Introducing `mix release`

mix release creates an OTP release. Think of it as a complete, self-contained package of your Elixir application and its dependencies.

It includes the Erlang VM, your compiled code, and all necessary scripts to start, stop, and manage your application as a standalone service.

Benefits of Using Releases

Using releases offers several key advantages:

  • Self-contained: No need for Mix or Elixir installation on the server.
  • Faster Startup: Pre-compiled and optimized for production.
  • Production-ready: Designed for daemonization and supervision.
  • Hot Code Swapping: Supports upgrading running systems without downtime (advanced).

Generating Your First Release

To create a release, first ensure your project has a supervisor. Most Phoenix projects and projects created with mix new my_app --sup already have one.

Then, simply run the mix release command. This will compile your project and its dependencies for the production environment.

mix new my_release_app --sup
cd my_release_app
mix deps.get
mix release

Exploring the Release Structure

After running mix release, you'll find your release in _build/prod/rel/your_app_name/.

Inside, you'll see a bin directory containing a script to manage your app, lib with all compiled dependencies, and releases with version-specific files.

my_release_app/
├── _build/
│   └── prod/
│       └── rel/
│           └── my_release_app/
│               ├── bin/
│               │   └── my_release_app (start/stop script)
│               ├── lib/
│               ├── releases/
│               └── erts-...
├── config/
├── lib/
└── mix.exs

Running Your Released Application

To start your application from a release, use the generated script in the bin directory. You can start it in the foreground or as a daemon.

For a production environment, you'd typically start it in the background.

# Start in foreground (for testing)
_build/prod/rel/my_release_app/bin/my_release_app start_iex

# Start as daemon (production)
_build/prod/rel/my_release_app/bin/my_release_app start

# Stop a running daemon
_build/prod/rel/my_release_app/bin/my_release_app stop

Runtime Configuration with `runtime.exs`

For production deployments, you often need to configure your application based on its environment (e.g., database credentials, API keys).

mix release uses config/runtime.exs, which is executed after the release is built and before the application starts. This is perfect for reading environment variables.

# config/runtime.exs
import Config

config :my_release_app, 
  database_url: System.get_env("DATABASE_URL"),
  api_key: System.get_env("API_KEY")

Upgrades and Downgrades (Advanced)

One of the most powerful features of OTP releases is the ability to perform hot code upgrades. This means you can update your running application with new code without stopping it, leading to zero downtime deployments.

While this is an advanced topic, `mix release` lays the groundwork for it by packaging your application in a way that allows for version management and patching.

Release Benefits Check

Which of the following are key benefits of using mix release for deploying an Elixir application?

Recap: Ready for Deployment!

You've learned that mix release is the standard way to package Elixir applications for production. It creates a self-contained, optimized bundle, independent of the Mix toolchain.

Releases offer faster startup, robust daemonization, and support for advanced features like hot code upgrades. Coupled with config/runtime.exs, they provide a powerful and flexible deployment solution.

Frequently asked questions

Is the “Building Releases with Mix Release” lesson free?

Yes — the full text of “Building Releases with Mix Release” is free to read here on the web, and the Elixir & Phoenix: Scalable Backend Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Elixir & Phoenix: Scalable Backend Development course, upgrade to CoddyKit PRO.

What will I learn in “Building Releases with Mix Release”?

Create self-contained and ready-to-deploy releases of your Elixir application using `mix release`. You practise Elixir & Phoenix: Scalable Backend Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Elixir & Phoenix: Scalable Backend Development?

No prior experience is required. Elixir & Phoenix: Scalable Backend Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Building Releases with Mix Release” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Elixir & Phoenix: Scalable Backend Development lesson?

Yes. Every Elixir & Phoenix: Scalable Backend Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Building Releases with Mix Release
  2. Containerization with Docker
  3. Cloud Deployment Strategies
  4. Zero-Downtime Deploys and Hot Upgrades
← Back to Elixir & Phoenix: Scalable Backend Development