How to Installing Elixir and Erlang With ASDF

ASDF, in the context of software development, is a powerful and versatile version manager. It allows you to easily:

  • Install and manage multiple versions of tools and programming languages on your system.
  • Switch between different versions on a per-project basis, giving you complete control over your development environment.
  • Avoid conflicts and ensure compatibility between projects using different versions of the same tool.

Many programming languages regularly release new versions that add or deprecate features, fix bugs, and introduce breaking changes. To help developers switch between versions easily, several language communities have version managers (like NVM for Node.js or Rbenv for Ruby). When you need to switch versions of multiple languages at once, however, the ASDF version manager ensures each project has the environment it needs.

This is especially important in Elixir projects, which require the Erlang runtime. In this tutorial, you’ll learn how to install specific versions of Elixir and Erlang/OTP using the ASDF version manager on macOS or Linux.

Install ASDF

The ASDF version manager is a command-line tool that is available on GitHub. It uses curl and git to install various languages.

Install Prerequisites

To install the curl and git utilities, run:

brew install coreutils curl git  # on macOS with Homebrew
sudo apt install curl git        # on Linux

You can learn more about Homebrew on macOS here.

Clone ASDF

With the prerequisites installed, now clone the ASDF project:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf

If you ever wish to remove ASDF, you can do so by removing .asdf from your home directory and undo the configuration changes described below.

Configure Your Shell

Finally, include ASDF in your shell's configuration. For zsh, add the following to ~/.zshrc:

. $HOME/.asdf/asdf.sh

Alternatively, if you use oh-my-zsh, add asdf to your plugin configuration. To include ASDF in your configuration when using a different shell, consult the documentation.

Install Plugins

ASDF uses a plugin system to support multiple languages. For a typical Elixir project, you will need the Elixir and Erlang plugins:

asdf plugin add erlang
asdf plugin add elixir

If your project requires Node.js, you can also install the nodejs plugin.

Install Erlang/OTP

With ASDF and its plugins installed, you can now install Elixir and Erlang. If your project has a .tool-versions file with entries for elixir and erlang, you can install the correct versions by running the following from inside the project:

asdf install

The .tool-versions file is much like .nvmrc and .ruby-version files, except that it lists the names and versions of multiple languages. In general, the names in this file should match the names of the language's plugin (e.g. nodejs for Node.js).

If you do not yet have a .tool-versions file, or want to install Elixir and Erlang globally, use the following to see a list of all available Erlang/OTP versions:

asdf list-all erlang
# ...
23.2
23.2.1
23.2.2
# ...

Unlike other version managers, ASDF requires you to specify a precise version of the language to install. To install version 23.2.1 of Erlang, run:

asdf install erlang 23.2.1

Warning: This installation will take some time while it compiles Erlang from source.

Erlang will compile modules based on the available libraries from your system. For example, some features (such as the built-in observer) require wx libraries. You may see messages during the installation about omitted modules, which will not affect the rest of the runtime.

Install Elixir

Once the Erlang runtime is installed, you are ready to install Elixir. To see a list of all available versions, run:

asdf list-all elixir
# ...
1.11.2
1.11.2-otp-21
1.11.2-otp-22
1.11.2-otp-23
# ...

Notice that each Elixir release has multiple versions compiled with different major versions of Erlang/OTP. To maximize compatibility between Elixir and the Erlang runtime, choose a -otp-XY version that matches the major version of the runtime you installed in the previous step. For example:

asdf install elixir 1.11.2-otp-23

Installing Elixir takes significantly less time than installing Erlang/OTP.


Set Versions

Now that you have Elixir and Erlang/OTP installed, you can save your chosen versions in a project. From the root of the project, run:

asdf local erlang 23.2.1
asdf local elixir 1.11.2-otp-23

Replace the versions above with those you used during installation. This will create a .tool-versions file in your project, which will instruct ASDF which versions to use. If you'd like to set a global, or default, version, run:

asdf global erlang 23.2.1
asdf global elixir 1.11.2-otp-23

This will create a .tool-versions file in your home directory. ASDF will use these versions whenever a project doesn't specify versions of its own.

ASDF is a popular version manager for Elixir projects because it manages both Elixir and Erlang versions. Include a .tool-versions file in your projects to help contributors get up-and-running quickly, and don't forget to leverage the -otp-XY versions of Elixir for the best compatibility.

Thanks for reading !!!
 

#elixir #erlang #asdf

How to Installing Elixir and Erlang With ASDF
6 Likes15.05 GEEK