← Back to All Posts

Installing Elixir with asdf 🚀

June 17, 2024

As a developer, I’m always on the lookout for new and exciting programming languages to explore. One language that has recently caught my attention is Elixir - a dynamic, functional language designed for building scalable and maintainable applications. In this comprehensive tutorial, I’ll walk you through the process of installing Elixir using a package manager, so you can get started on your Elixir journey.

Step 1: Install a Version Manager 📦

To begin, we’ll need to install a version manager to handle multiple versions of Elixir and Erlang (the underlying runtime for Elixir) on our system. One popular choice is ASDF, a version manager that allows you to easily switch between different language versions.

If you don’t have Homebrew (a popular package manager for macOS) installed, you’ll need to do that first. Open your terminal and run the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is installed, we can install ASDF:

brew install asdf

Next, we’ll need to add the ASDF script to our shell configuration file (either `.zshrc` or `.bashrc`, depending on your setup). For macOS Catalina and later, which use the Z shell (zsh) by default, run the following command:

echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

This will add the necessary script to your shell configuration, allowing ASDF to be loaded when you open your terminal.

Step 2: Install Erlang 🤖

Elixir is built on top of the Erlang virtual machine (VM), so we need to install Erlang before we can install Elixir. ASDF makes this process easy:

asdf plugin add erlang
asdf install erlang latest
asdf global erlang latest

The first command adds the Erlang plugin to ASDF, the second command installs the latest version of Erlang, and the third command sets the global Erlang version to the latest release.

Step 3: Install Elixir 💻

Now that we have Erlang installed, we can move on to installing Elixir. Again, we’ll use ASDF for this:

asdf plugin add elixir
asdf install elixir latest
asdf global elixir latest

These commands follow the same pattern as the Erlang installation: add the Elixir plugin, install the latest version, and set the global Elixir version.

Step 4: Verify the Installation 🔍

To ensure that Elixir and Erlang have been installed correctly, we can run the following commands in your terminal:

elixir --version
erlang --version

You should see the version numbers for both Elixir and Erlang displayed, confirming that the installation was successful.

Step 5: Explore Elixir 🔍

Now that you have Elixir installed, you’re ready to start exploring this powerful language. Elixir is a dynamic, functional language that is designed to be highly concurrent and fault-tolerant. It is built on top of the Erlang VM, which is known for its reliability and scalability in the telecommunications industry.

One of the key features of Elixir is its focus on immutability. In Elixir, you can’t modify a variable after it’s been initialized. Instead, you create new values by transforming existing ones through function calls. This approach helps to prevent unexpected side effects and makes it easier to reason about your code.

Elixir also has a strong emphasis on concurrency, which allows it to handle large data volumes and high-throughput applications. The Erlang VM’s lightweight processes and message-passing system make it easy to build scalable, distributed systems.

To get started with Elixir, you can try writing some simple programs, exploring the language’s syntax and features. The Elixir community is also very active, with a wealth of resources available online, including tutorials, libraries, and open-source projects.

Conclusion 🎉

In this tutorial, we’ve covered the steps to install Elixir using a package manager, specifically ASDF. By setting up a version manager, you can easily switch between different versions of Elixir and Erlang, making it easier to work on multiple Elixir projects with different requirements.

With Elixir now installed, you’re ready to dive into the world of functional programming and build scalable, maintainable applications. Enjoy your Elixir journey, and don’t hesitate to reach out to the community if you have any questions or need support along the way!