• Get In Touch
June 5, 2017

How to Install Erlang on Ubuntu 16.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Erlang is a general-purpose programming language or runtime environment designed at the Ericsson Computer Science Laboratory. In the Erlang runtime environment the code is compiled to bytecode and runs inside a virtual machine. So Erlang much like Java can run anywhere. It was originally designed for soft real-time applications where you need to handle connections or routing for a very high number of users. It was mainly developed for the large telecommunication systems but now it is also used in several other fields like banking, instant messaging and computer telephony as well.

There are some applications and systems where Erlang has a significant role:
RabbitMQ, message-oriented middleware is written in the Erlang programming language. WhatsApp uses Erlang to run messaging servers. Many large companies like Amazon, Yahoo!, Facebook, Motorola and Github are using Erlang.

Erlang is defined as a functional programming language. Erlang uses the actor model, and each actor is a separate process in the virtual machine. In Erlang runtime environment multiple tasks can be run at the same time. Erlang is used widely because of it’s ability to recover from errors. It has integral support for distribution and concurrency.

Several other key features that Erlang has:

  • Hot code replacement, to upgrade the code you don’t need to stop and restart your system.
  • Reliability-oriented standard library.
  • Lightweight user-space threads.
  • It is free and can be used for any open-source, freeware or commercial projects.
    Some open-source projects based on Erlang are ejabberd, Flussonic, Riak, RabbitMQ, and Dynomite.
  • Cross-platform, like Java it can run on different platforms.
  • Fault-tolerant and scalable.

This tutorial will help you to install Erlang on Ubuntu 16.04 (Xenial Xerus) operating system. There is an example; a simple Hello World program is explained in this tutorial that will help you to understand how to create, compile and run a program in Erlang programming language.

Requirements

  • A server running Ubuntu 16.04.
  • In this tutorial, we’ll use a non root account with sudo privileges configure on our server hence we’ll use sudo before the commands.

Updating the Base System

This tutorial assumes that we have a clean Ubuntu Server 16.04. Before installing Erlang, let’s update our base system to the latest update:

$ sudo apt-get update
$ sudo apt-get -y upgrade

Adding Repository entry

You can simply download Erlang repository package from its official website and install on your system.

To add Erlang Solutions repository (including Erlang Solutions public key for apt-secure) to your system, call the following commands:

$ wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
$ sudo dpkg -i erlang-solutions_1.0_all.deb

Install Erlang on Ubuntu

To retrieve the updated package lists and refresh the repository cache run following command:

$ sudo apt-get update

Install either the erlang package or the esl-erlang package. You can install erlang package using the following command:

$ sudo apt-get install erlang

It will ask you if you want to continue with the installation, press y and then enter.

Alternatively, you can do the complete Erlang installation. It includes the Erlang/OTP platform and all of its applications by running the following command:

$ sudo apt-get install esl-erlang

It will ask you if you want to continue with the installation, press y and then enter.

Make sure that you install only one of the above-mentioned packages.


erlang package

The Erlang/OTP platform is a complex system composed of many smaller applications (modules). If you want to download and install a particular selection of modules, then you don’t need to install complete OTP ( Open Telecom Platform) Suit, because it is possible to install these smaller packages of OTP without launching the erlang package.

The OTP libraries provide a complete set of easy-to-use components for building robust distributed applications.

esl-erlang package

The esl-erlang package is a file containing the complete installation: it includes the Erlang/OTP platform and all of its applications.


Erlang Hello World Program

Erlang is easy to learn. An experienced programmer can start writing useful code after a couple of days of learning Erlang. The syntax may look a little different if you’re coming from other programming languages like Java, Ruby, or Python, but it doesn’t take long to get used to.

So let’s take an example and start with a simple “hello world!” program on Erlang.

Create

First, create a file helloworld.erl using vi text editor.

To do this run the following command:

$ vi helloworld.erl

Now in the vi text editor go to the Insert mode by pressing letter ‘i’.
add the following content:

% hello world program
-module(helloworld).
-export([start/0]).
start() ->
io:fwrite("Hello World!\n").

Don’t forget the full-stop (“period” in American English) at the end of each command, as shown in the example.

The ModuleName needs to be same as the file name (do not include the extension .erl), as shown in the example.

Syntax
-module(ModuleName).

Example:
-module(helloworld).

Switch to the Command mode by pressing ‘Esc’ key.

Now type “:wq” and press enter to save the changes and quit vi editor.

The following explanation will help you to understand the syntax of the above program:

  1. To add the comments in the program use % sign.

  2. The module statement is like adding a namespace as in any programming language. In this program, we are mentioning that this code is a part of a module called helloworld.

  3. We are using the export function to use any function defined within the program. In the above program we are defining a function called start, and to use the start function, we have to use the export statement.

  4. The slash “/” symbol is used along with the function to define the number of parameters which is accepted by the function. In the above example , the /0 means that our function ‘start’ accepts 0 parameters.

  5. io is an another module which has all the required Input Output functions in Erlang. We are using the fwrite function to output “Hello World” to the console.

Compile

Compile the hello world program using below command.

$ erlc helloworld.erl

The above command will create a file helloworld.beam in the current directory.

Run

Now, run your program using below command.

$ erl -noshell -s helloworld start -s init stop

Output

You will get the following output of your program on your terminal:

ubuntu@ip-172-31-28-82:~$ erl -noshell -s helloworld start -s init stop
Hello World!

Installing HiPE

This is an optional part. HiPE stands for High-Performance Erlang Project. It is a native code compiler for Erlang. In most cases, it positively affects performance. If you want to download it, call the following command:

$ sudo apt-get install erlang-base-hipe

This will replace the Erlang/OTP runtime with a HiPE supported version. Other Erlang applications do not need to be reinstalled.

If you want to come back to the standard runtime, call the following command:

$ sudo apt-get install erlang-base

Conclusion

In this tutorial, we have learned how to install Erlang on Ubuntu 16.04. We have also seen an example to understand how to create, compile and run a program in Erlang.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]