A Beginner's Guide to Installing Elixir with asdf

If you are new to the world of Elixir and want to start developing your own Elixir projects, one of the first steps you need to take is installing Elixir on your machine. In this guide, we will walk you through the process of installing Elixir with asdf, a flexible version manager that allows you to easily manage different programming languages and their respective versions.

What is asdf?

As you may be aware, asdf is a version manager that simplifies the installation and management of various programming languages. If you have used package managers like Homebrew before, you will notice some similarities with asdf. With asdf, you can switch between different tool/runtime versions of a language effortlessly without worrying about manually installing and managing different versions of programming languages on your system. It provides a centralized and efficient way to handle multiple language versions, making it a valuable tool for developers. One of the key benefits of using asdf is its compatibility with multiple operating systems. asdf is compatible with a wide range of operating systems, including:

  • Linux
  • macOS
  • Windows

Step-by-Step Guide to Installing Elixir with asdf

Whether you’re working on a project that requires a specific version of Elixir or you want to experiment with different versions of Erlang, asdf makes it incredibly simple to switch between them without any hassle. We would approach setting up asdf in two steps

  1. First, you’ll need to install asdf itself. To do this, open your terminal and follow the instructions specific to your operating system provided in the official asdf Github.com documentation and tutorials.
  2. Once you have asdf installed, you need to add the Elixir plugin associated plugin dependencies. This plugin allows asdf to manage Elixir versions. In your terminal, run the following command to add the Elixir plugin:
$ asdf plugin add elixir

Depending on the specific OS, and shell runtime being used, you may need to also setup completions manually for asdf. Fortunately, the install asdf documentation clearly specifies installation instructions for every OS combination.

Installing Erlang with asdf

Now that you have asdf and the Elixir plugin set up, it’s time to install Erlang, which is a prerequisite for running Elixir. Erlang is a programming language that provides the foundation for Elixir, and installing it is essential to ensure that Elixir functions properly on your system.

Installing Erlang can be done through asdf, making the process straightforward and hassle-free. Simply open your terminal and run the following command:

$ asdf install erlang

This command will automatically download and install the latest stable version of Erlang on your system. However, if you need a specific version of Erlang for your project, you can specify it in the command, and asdf will take care of the rest.

$ asdf install erlang <version>

Once the installation is complete, you’re all set to start using asdf with Elixir. You can now effortlessly switch between different versions of Elixir using asdf, ensuring that your projects are always compatible with the required Elixir version.

After the installation is complete, you can verify that Erlang is successfully installed by running the following command:

$ erl

This will start the Erlang shell, where you can interactively execute Erlang code and test your installation. If the shell starts without any errors, it means Erlang is installed correctly.

Now that you have Erlang installed, you can proceed to install Elixir.

Ensuring the Right Elixir OTP Version

Before installing Elixir, it’s important to determine the appropriate OTP version required for your Elixir version. You can find this information in the Elixir documentation or the project you are working on.

The OTP version is the underlying Erlang/OTP release that Elixir is built on (for example, Erlang-OTP-24). Each Elixir version has a specific OTP version requirement to ensure compatibility and optimal performance. It’s crucial to install the correct OTP version before installing Elixir.

To find the OTP version required for your Elixir version, you can refer to the Elixir documentation.

Keeping asdf and Elixir plugins current

Before installing Elixir, it’s a good practice to ensure that you configure the latest version of asdf and the Elixir plugin.

To update asdf and the Elixir plugin, open your terminal and run the following commands:

$ asdf plugin update --all
$ asdf update

The first command updates all the installed plugins, including the Elixir plugin. The second command updates asdf itself.

Install Elixir Versions Now, let’s install the desired Elixir version using asdf. In your terminal, run the following command:

$ asdf install elixir <version>

Replace with the [specific version of Elixir](/blog/elixir-releases-phoenix-gigalixir/) you want to install. Make sure to use the correct version number to ensure compatibility with your project config or the specific Elixir features you require.

asdf will automatically download the specified version of Elixir and install it on your system. This process may take a few minutes, depending on your internet connection speed and system resources.

Once the installation process is complete, you’re ready to activate your Elixir and Erlang versions. Activating a specific version sets it as the default version to be used in your development environment.

Activating Your Elixir and Erlang Versions

To activate the Elixir and Erlang versions you just installed, run the following commands in your terminal:

$ asdf global elixir <version>
$ asdf global erlang <version>

Replace with the available versions you installed. If you are running multiple projects, which require different versions, then take a look at the “asdf local” command. You can specify the version in the project directory using the following commands:

$ asdf local elixir <version>
$ asdf local erlang <version>

Cleaning up the installation

After successfully installing and activating the desired Elixir and Erlang versions, it’s a good practice to remove any old or unused Elixir or Erlang plugins from your system to free up space. In your terminal, run the following commands:

$ asdf uninstall elixir <old_version>
$ asdf uninstall erlang <old_version>

Replace with the specific versions you want to remove.

Expand Your asdf Toolkit with Other Useful Plugins

asdf is not limited to Elixir and Erlang - it supports a variety of programming languages. You can expand your asdf toolkit by adding other useful plugins for languages such as Ruby, Node.js, and Python. Consult the official asdf docs for a list of available plugins. To find out what asdf plugins are already installed you can use the following asdf list command as below:

$ asdf plugin list all

Get Ready for Elixir and Phoenix with asdf

Congratulations! You have successfully installed Elixir with asdf. With the asdf version manager, you can easily switch between different Elixir and Erlang versions depending on the requirements of your projects. Now, you’re ready to unleash the power of Elixir and dive into coding. Happy coding!

Now that you’re equipped with Elixir and asdf, take the next step in your developer journey with Gigalixir. As a platform designed specifically for Elixir and Phoenix applications, Gigalixir offers world-class support to enhance your coding experience. Whether you’re working with Go, Django, Python, or Node, our customer support is here to assist you. Sign up for free today and experience the ease of deploying your Phoenix and Elixir apps with Gigalixir.