How to Install Erlang on Ubuntu 16.04

How to Install Erlang on Ubuntu 16.04

Overview

In this tutorial we’ll learn how to install Erlang on Ubuntu 16.04 Xenial Xerus. Erlang is a programming language used to build scalable real time systems with high availability as main requirement.

Initially being used in telecoms and banking industry but the now its usage expanded to e-commerce to chat systems backend like WhatsApp and Facebook Chat.

Erlang website provide complete information about this language.

Objective

  • Learn to install Erlang from Ubuntu 16.04 Repository.
  • Learn to install Erlang from erlang-solutions.com repository.
  • Create Erlang Hello World application, compile and run it.

Install Erlang From Ubuntu 16.04 Repository

Erlang already shipped with Ubuntu 16.04. The version shipped with Ubuntu 16.04 is Erlang 18.3.

To install Erlang from Ubuntu repository you can use commands below.

[code lang=text]
sudo apt-get update
sudo apt-get install erlang
[/code]

Install Erlang from erlang-solutions.com

If you want to use the latest stable version of Erlang you can install pre-packaged binary for Ubuntu 16.04 from erlang-solutions.com repository.

Add Erlang Solutions public key for apt-secure

[code lang=text]
wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc
sudo apt-key add erlang_solutions.asc
[/code]

Add Erlang Solutions repository config. Create file /etc/apt/sources.list.d/erlang-solutions.list with contents below.

[code lang=text]
deb http://binaries.erlang-solutions.com/debian xenial contrib
[/code]

As alternative to method above, we can also add the key and repository config by installing erlang-solutions package using command below.

[code lang=text]
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
sudo dpkg -i erlang-solutions_1.0_all.deb
[/code]

Update apt metadata using command below

[code lang=text]
sudo apt-get update
[/code]

There are multiple erlang packages that we can install from Erlang Solutions repository.

If you have limited space you can install erlang-base package. You can install it using command below.

[code lang=text]
$ sudo apt-get install erlang-base
[/code]

If you need more complete installation of Erlang you can install erlang package using command below

[code lang=text]
$ sudo apt-get install erlang
[/code]

erlang solutions repository also provide esl-erlang packages. You can install it using command below

[code lang=text]
$ sudo apt-get install esl-erlang
[/code]

Erlang Shell

Erlang comes with shell application called erl. Let’s open Erlang shell.

[code lang=text]
~$ erl
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [kernel-poll:false]

Eshell V9.0 (abort with ^G)
1>
[/code]

We got Erlang/OTP version 20. This is the latest stable version of Erlang from Erlang solutions website.

To try this shell, on the 1> prompt input code below

[code lang=text]
io:fwrite("Hello Erlang From Xenial! – Howtodojo \n").
[/code]

Command above will provide output

[code lang=text]
Hello Erlang From Xenial! – Howtodojo
ok
[/code]

To exit from erlang shell press CTRL + C twice.

Hello Erlang From Xenial

Now you have erlang installed. Let’s create sample hello world application and compile it

Create new file called installerlangxenial.erl with contents below.

[code lang=text]
% hello erlang program
-module(installerlangxenial).
-export([start/0]).

start() ->
io:fwrite("Hello Erlang From Xenial! – Howtodojo \n").
[/code]

Compile the code above using erlc command

[code lang=text]
erlc installerlangxenial.erl
[/code]

Command above will generate file installerlangxenial.beam

Run the compiled file using command below

[code lang=text]
erl -noshell -s installerlangxenial start -s init stop
[/code]

We can also run code above using one liner command below

[code lang=text]
erl -noshell -eval 'io:fwrite("Hello Erlang From Xenial! – Howtodojo \n"), init:stop().'
[/code]

Summary

In this tutorial we learned how to install Erlang on Ubuntu 16.04. We tried using Erlang shell and create simple hello world application using Erlang.

It’s time to have fun with Erlang.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.