How-to Install Erlang on Ubuntu 14.04

What is Erlang

In this tutorial we’ll learn how-to Install Erlang on Ubuntu 14.04. Erlang is a programming language used to build massively scalabe soft real-time systems with requirements on high availability.

Erlang is being used on telecoms and banking, lately it’s also being used on e-commerce, computer telephony and instant messaging service.

Erlang’s runtime system has built-in support for concurrency, distribution and fault tolerance.

One of the startup that [use Erlang on its backend][1] is WhatsApp. Facebook also [use erlang on Facebook Chat][2].

You can learn more about Erlang from [Erlang website][3]

Install Erlang from Ubuntu Repository

Ubuntu 14.04 (Trusty Tahr) have [erlang][4] on its universe repository. The version that shipped with Trusty is Erlang 16. To Install Erlang from ubuntu repository you can run command below :

[bash]
sudo apt-get update
sudo apt-get install erlang
[/bash]

Install Erlang from erlang-solutions.com

If you want to use the most recent stable version of Erlang you can install Erlang from [erlang-solutions.com repository][5].

Before we add erlang-solutions repository, we need to add erlang-solution public key for apt-secure.

wget -c -O- http://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo apt-key add -

After adding key, we’ll add erlang-solutions repository to a file under /etc/apt/sources.list.d/erlang_solutions.list:

echo "deb http://packages.erlang-solutions.com/ubuntu trusty contrib" | sudo tee -a /etc/apt/sources.list.d/erlang_solutions.list > /dev/null

Before we install let’s let apt re-read repositories metadata:

sudo apt-get update

If you have limited space, you can install only base package of Erlang from erlang-base package:

$ sudo apt-get install erlang-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
erlang-crypto erlang-syntax-tools
Suggested packages:
erlang-tools erlang erlang-manpages erlang-doc
The following NEW packages will be installed:
erlang-base erlang-crypto erlang-syntax-tools
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 7410 kB of archives.
After this operation, 14.9 MB of additional disk space will be used.
Do you want to continue? [Y/n]

```

Type Y as answer to question above. As you can see from the output above erlang-base only need 14.9 MB disk space.

If you have plenty of disk space, of couse you can choose erlang package to install :

sudo apt-get -y install erlang

```

The command above will require 197 MB of disk space to install erlang and its dependencies.

    ...
    0 upgraded, 84 newly installed, 0 to remove and 0 not upgraded.
    Need to get 81.1 MB of archives.
    After this operation, 197 MB of additional disk space will be used.
    

Erlang Solutions also provides `esl-erlang` that contain complete installation. It include Erlang/OTP platform and all of its application. please note that some packages have dependencies of erlang and not esl-erlang.

## Erlang Shell

Erlang have shell called erl. To open erl you can just run erl

    $ erl
    Erlang/OTP 18 [erts-7.2]
    
    [source][/source]
    
    [64-bit] [async-threads:10] [kernel-poll:false]
    
    Eshell V7.2 (abort with ^G)
    1>
    

We can see above that the Erlang version is 18 which is the latest stable erlang version at the time of this writing.

## Hello World in Erlang

Let's do a famous Hello World on erlang. Create a file `helloerlang.erl` with contents below :

    % hello erlang program
    -module(helloerlang).
    -export([start/0]).
    
    start() ->
    io:fwrite("Hello Erlang! - Howtodojo \n").
    

We will compile this erlang source code using `erlc` :

    erlc helloerlang.erl
    

The command above will create binary file `helloerlang.beam`. We can run the binary program using erl.

    $ erl -noshell -s helloerlang start -s init stop
    Hello Erlang! - Howtodojo
    

We can also use oneliner code below to print hello world :

    erl -noshell -eval 'io:fwrite("Hello Erlang! - Howtodojo\n"), init:stop().'
    

## Summary

In this tutorial we already learn how to install erlang from Ubuntu repository and also from erlang-solutions repository. We also learn how to use erlang shell and also create Erlang Hello World program by compiling source code using erlc. We also create one liner Hello World program using erl. Now you're ready to start learning and developing your application using erlang. Until then, have Fun!

 [1]: http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html
 [2]: https://www.facebook.com/notes/facebook-engineering/facebook-chat/14218138919/
 [3]: http://www.erlang.org/
 [4]: http://packages.ubuntu.com/trusty/erlang
 [5]: https://www.erlang-solutions.com/resources/download.html