2018 / 03 / 08
2023 / 12 / 12
Install Elixir in Linux

The easiest way to install Elixir in Linux is through asdf, period.


GitHub for asdf-erlang | GitHub for asdf-elixir

Version managers are great. With them you are able to install multiple versions of the languages you use.
I’ve been using asdf to install Erlang and Elixir with OTP support for quite some time now.

Install asdf

Clone the GitHub repository:

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

Add some lines to your .profile and .bashrc files:

echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.profile
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc

Make changes effective immediately with:

source ~/.profile
exec $SHELL

If we add asdf.sh to ~/.profile instead of ~/.bashrc, it will have the side effect of allowing applications started through dmenu —for i3 users— to be able to call asdf installed commands.

This is because stuff in ~/.profile gets loaded when you log in into your account. Thus, anything there will be available to other programs run through dmenu or desktop icons.

On the other hand, stuff in ~/.bashrc gets loaded every time you open a terminal. Thus, another way to have VSCode work with asdf installed commands, would be to just start code from a terminal.

Update asdf

To update to the latest stable version just type:

asdf update

Install Erlang and Elixir

Let’s get some dependencies for Erlang —we need WxWidgets so we can use :observer.start:

sudo pacman -S base-devel glu libpng libssh mesa ncurses unixodbc wxwidgets-gtk3

For Ubuntu you need these dependencies:

sudo apt install build-essential autoconf m4 libncurses5-dev libwxgtk3.0-gtk3-dev \
libgl1-mesa-dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev \

Finally install Erlang and Elixir:

asdf plugin-add erlang
asdf list-all erlang
KERL_BUILD_DOCS=1 asdf install erlang 26.2.2
asdf global erlang 26.2.2

asdf plugin-add elixir
asdf list-all elixir
asdf install elixir 1.16.0-otp-26
asdf global elixir 1.16.0-otp-26

To enable the REPL history in IEx:

echo -e '\nexport ERL_AFLAGS="-kernel shell_history enabled"' >> ~/.bashrc

If using Visual Studio Code try out the ElixirLS extension.

Install Hex

Let’s take on Hex the package manager now:

mix local.hex

You can print some info about your Elixir installation with:

mix hex.info

Install Rebar3

mix local.rebar

Install Phoenix

For completeness’ sake let’s install the latest version of Phoenix:

mix archive.install hex phx_new

# Want to install a specific version?
# mix archive.install hex phx_new 1.5.7
# mix archive.install hex phx_new 1.6.0-rc.0

That’s it!

Some useful libraries