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.
You can learn more about Erlang from Erlang website
Install Erlang from Ubuntu Repository
Ubuntu 14.04 (Trusty Tahr) have erlang on its universe repository. The version that shipped with Trusty is Erlang 16. To Install Erlang from ubuntu repository you can run command below :
sudo apt-get update
sudo apt-get install erlang
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.
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
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
$ 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 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
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().'
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!