Elixir & Erlang Setup with asdf Version Manager

by on

I started web development 2 years back and Ruby on Rails became the default choice. Rails is a beginner's heaven but soon you realise about performance overheads and other pain points.

Elixir came as the shiny new thing and I got my feet wet in it at the start. Built my first blog app(duh that's how I started to learn Rails). Soon I was learning bits and pieces and reading about the Awesomeness that is- Elixir.

Why Elixir? I have a list of reasons like personal growth as a developer, who is not language or framework bound, its ability to build scalable apps with better performance and more.

The only approach to get the hang of a new language & framework would be through continuous structured learning and building 'stuff'. Writing about the process only adds to the learning. Starting with baby steps, here's how I set up Elixir and Erlang.

Elixir runs on the Erlang VM and so requires Erlang 18.0 or later as a prerequisite. Having to manage multiple versions of Elixir for my different apps made it necessary to have a version manager.

A Little About the asdf Version Manager

The asdf version manager fits all Elixir & Erlang version management needs and some more. The source can be found here https://github.com/asdf-vm/asdf and its creator here https://github.com/HashNuke.
The primary reason for choosing asdf is that it can help with version management of Node.js, Ruby, Python, Postgres and more. Its as simple as adding the plugin for the language desired and then one can install/uninstall or switch between versions.
Instead of installing 3 different version managers to manage Elixir, Erlang and Node.js , we can use asdf for all three.

Installing the asdf Version Manager

Install prerequisite dependencies

For Ubuntu

sudo apt-get install automake autoconf libreadline-dev libncurses-dev libssl-dev libyaml-dev libxslt-dev libffi-dev libtool unixodbc-dev

For Mac

brew install automake autoconf openssl libyaml readline ncurses libxslt libtool unixodbc

Install the Version Manager

Clone the git repo of the manager

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.1.0
# For Ubuntu or other linux distros
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
echo '. $HOME/.asdf/asdf.sh' >> ~/.zshrc
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc

# OR for Mac OSX
echo '. $HOME/.asdf/asdf.sh' >> ~/.bash_profile
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bash_profile

Reload terminal session to ensure changes are effective or we can open a new terminal and continue
This creates the .asdf folder in your home directory. All versions of your language that you install with asdf will be in the ~/.asdf/installs directory.

Installing Erlang using asdf Version Manager

Plugins are how asdf understands how to handle different packages.

Add the asdf Erlang plugin - https://github.com/asdf-vm/asdf-erlang

$> asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git 

Check if Erlang Plugin is installed by listing all plugins

$> asdf plugin-list | grep erlang

You should see 'erlang' there

To see the Erlang versions which are available

$> asdf plugin-update erlang
$> asdf list-all erlang 

Install the desired version

$> asdf install erlang 19.0

This will download & configure Erlang.

To tell asdf which version of erlang to use by default, Edit/Create .tool-versions in the app directory and put the plugin name followed by version in the file

$> vim {app-directory}/.tool-versions 

erlang 19.0

Check if Erlang is installed correctly by calling upon the interactive shell

$> erl

Installing Elixir Using asdf Version Manager

Install the asdf Elixir plugin - https://github.com/asdf-vm/asdf-elixir

$> asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git 

To see Elixir versions which are available

$> asdf plugin-update elixir
$> asdf list-all elixir 

Install the desired elixir version

$> asdf install elixir 1.3.2 

To tell asdf which version of elixir to use by default, Edit/Create a .tool-versions file in the app directory and put the plugin name followed by version in the file

$> vim {app-directory}/.tool-versions

erlang 19.0
elixir 1.3.2

Installing Node.js Using asdf Package Manager

To build web apps with Phoenix Framework we need Node.js which can be easily installed and managed using asdf. Install the asdf Node.js plugin - https://github.com/asdf-vm/asdf-nodejs.git

$> asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git

To see the Node.js available versions

$> asdf plugin-update nodejs
$> asdf list-all nodejs 

Install the desired Node.js Version

$> asdf install nodejs 6.5.0

To tell asdf which version of Node.js to use, Edit/Create a .tool-versions file in the app directory and put the plugin name followed by Node.js version

$> vim {app-directory}/.tool-versions

erlang 19.0
elixir 1.3.2
nodejs 6.5.0

Managing Versions With asdf

Set Global Default Version
The global version which is to be used by default by any scripts that you run can be set by creating the .tool-versions file in the home directory.

$> vim ~/.tool-versions

erlang 19.0
elixir 1.3.2

To get the current version being used, you can use the plugin name to query like

$> asdf current erlang

=> 19.0 (set by /home/username/.tool-versions)

Set Versions In Your App Folder
Create the .tool-versions file inside your app folder and this will override the tool versions set in the global file in home directory.

$> cd /home/User/my/app/dir
$> vim .tool-versions

erlang 19.0
elixir 1.3.2

Finally... Set up's done and glad to see that I can control the versions I use confidently.

Here are a list of alternate options & references to install Elixir, Erlang & Node.js
Installation using popular package managers: http://elixir-lang.org/install.html
Version Manager for Elixir: https://github.com/taylor/kiex
Version Manager for Erlang: https://github.com/kerl/kerl
Version Manager for Node: https://github.com/creationix/nvm

Published in version-manager | Tagged with asdf, elixir, erlang, nodejs






Talk to us, that's always a good idea!