Installing Elixir on Linux

In order to develop elixir applications, you will need to install elixir itself, erlang because elixir is made for the erlang virtual machine, nodejs for compiling assets in phoenix, and you'll most likely want a RDBMS (relational database management system) such as postgresql or MySQL. These can of course be installed by your distribution's package manager - in fact, there are official instructions for doing so for various distributions here.

You may, however, find yourself developing projects under different versions of elixir, erlang, and possibly even your RDBMS. For such situations, it's useful to use a version manager (those from a ruby background may be familiar with chruby, rbenv, or rvm). This software allows you to install multiple versions of your tools, and switch between them (mostly) automatically, using a file that specifies the version in each project.

ASDF Version Manager

The asdf version manager allows version management of multiple different tools using a plugin system. Let's install asdf, then use it to install elixir, erlang, nodejs, and postgresql.

The README on the asdf page has excellent instructions (in fact the below are practically copied from there with modifications for our specific use case); if your environment is different from the standard - for example if you're using a shell other than bash - I'd recommend referring to them.

Step 1 - Install build tools and libraries

Many plugins will need tools to compile them, and libraries to link to. These need to be installed using your distribution's package manager:

deb based package managers (Debian/Ubuntu/Linux Mint/ElementaryOS):
sudo apt-get install automake autoconf libreadline-dev libncurses-dev libssl-dev libyaml-dev libxslt-dev libffi-dev libtool unixodbc-dev
rpm based package managers (Fedora/Red Hat/Scientific):
sudo yum install automake autoconf readline-devel ncurses-devel openssl-devel libyaml-devel libxslt-devel libffi-devel libtool unixODBC-devel
Other distributions may use different package names and package managers; a search for each of the names given should return your distro's equivalent.

Step 2 - Install asdf

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

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

Step 3 - Install all the plugins

If you have any trouble running these, start a new shell.

asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git
asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git
bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring
asdf plugin-add postgres https://github.com/smashedtoatoms/asdf-postgres.git

Step 4 - Install the version of tools we want

asdf install erlang 19.3
asdf install elixir 1.4.5
asdf install nodejs 8.2.1
asdf install postgres 9.6.3

Step 5 - Set these versions as your defaults

asdf global erlang 19.3
asdf global elixir 1.4.5
asdf global nodejs 8.2.1
asdf global postgres 9.6.3
Once you have a project to work on, you can add specific versions to a file called .tool-versions which asdf uses to choose which version to use when you switch into the project directory by replacing global in the above snippet with local.

Step 6 - Start postgres

pg_ctl start

Step 7 - Install Phoenix

Since we have just installed Elixir for the first time, we will need to install the Hex package manager as well. Hex is necessary to get a Phoenix app running (by installing dependencies) and to install any extra dependencies we might need along the way.

mix local.hex

Now that we have Hex installed we can install Phoenix

mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez

If you haven't coded before you will want to take a look at additional tools for some extra tools that will help you get started otherwise we're good to go! Let's go write some elixir!