lobo_tuerto's notes
How to install Elixir in Manjaro Linux
So you can play with OTP, Phoenix and friends!
Published on
2018 / 03 / 08
Updated on
2020 / 12 / 30
manjaro i3:20elixir:1.11erlang:22.3asdf:0.8

Link to the project asdf-elixir.
Link to the project asdf-erlang.

§ Version managers

I really like using version managers to install multiple coexisting versions for the dev languages that I use.

I’ve been using asdf the extendable version manager, to install Erlang and Elixir with OTP support, so far it’s been great.

§ Install asdf

Clone the GitHub repository:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.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 with:

source ~/.profile
exec $SHELL

We add asdf.sh to .profile and not to .bashrc, because it will have the side effect of allowing applications started through dmenu —for i3 users— to have the elixir command available.

This is because stuff in .profile gets loaded when you login into your account, so anything there will be available to commands run through dmenu or desktop icons.

But, stuff in .bashrc gets loaded everytime you open a terminal —so another way to have it work would be to just start code from the CLI.

§ Update asdf

To update to the latest stable version just type:

asdf update

§ Install Erlang and Elixir

Install some needed dependencies for Erlang —we need WxWidgets so we can use :observer.start:

sudo pacman -S unixodbc wxgtk
# You already have in your system most of what's needed
# The full list of dependencies would be:
# sudo pacman -S base-devel glu libpng libssh mesa ncurses unixodbc wxgtk

For Ubuntu you need these dependencies:

sudo apt install build-essential autoconf m4 libncurses5-dev libwxgtk3.0-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
asdf install erlang 23.2.1
asdf global erlang 23.2.1

asdf plugin-add elixir
asdf list-all elixir
asdf install elixir 1.11.2-otp-23
asdf global elixir 1.11.2-otp-23

To activate iex REPL history, add this to your .bashrc:

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

If you are using this awesome editor (hint: Visual Studio Code), you should try the ElixirLS extension.

§ Install Hex

Let’s take on Hex the package manager now:

mix local.hex

You can now print some info about your Elixir stack with:

mix hex.info

You’ll see something along the lines of:

Hex:    0.20.6
Elixir: 1.11.2
OTP:    23.2.1

Built with: Elixir 1.11.1 and OTP 21.3

§ Install Phoenix

Now let’s install the latest version of Phoenix —one of the best frameworks for writing web apps:

mix archive.install hex phx_new

# for a specific version:
# mix archive.install hex phx_new 1.5.7

To create a new API only web app, try with this command:

mix phx.new my-app --app my_app --module MyApp --no-html --no-webpack

If you want to follow up on building an API using Elixir, check this out:
Building a JSON API with Phoenix and Elixir

That’s it!

§ Links

Got comments or feedback?
Follow me on twitter