How to install Erlang and Elixir in CentOS

To Install Erlang and Elixir in CentOS 7

Erlang is a free source programming language to build adaptable soft real-time systems on high availability. This is used in telecoms, computer telephony,banking, e-commerce and instant messaging. It is widely used due to its fault tolerance, concurrency and distribution. Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Installation of Erlang and Elixir in CentOS is explained in this article.


To install dependencies

Before installing Erlang and Elixir, we need to install the following repo and dependencies.

[root@linuxhelp1 ~]# yum install epel-release -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Resolving Dependencies
-->  Running transaction check
--->  Package epel-release.noarch 0:7-6 will be installed
.
.
.
Installed:
  epel-release.noarch 0:7-6                                                                                                         

Complete!
[root@linuxhelp1 ~]# yum install gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel autoconf java-1.8.0-openjdk-devel wxBase.x86_64 -y
Loaded plugins: fastestmirror, langpacks
epel/x86_64/metalink                                                                                         | 4.8 kB  00:00:00     
 epel/x86_64/primary_db                                                                                | 4.3 MB  00:00:19     
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: epel.mirror.net.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Package 1:make-3.82-21.el7.x86_64 already installed and latest version
Package 1:openssl-devel-1.0.1e-51.el7_2.5.x86_64 already installed and latest version
Package autoconf-2.69-11.el7.noarch already installed and latest version
Resolving Dependencies
-->  Running transaction check
--->  Package gcc.x86_64 0:4.8.5-4.el7 will be installed
-->  Processing Dependency: cpp = 4.8.5-4.el7 for package: gcc-4.8.5-4.el7.x86_64
-->  Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-4.el7.x86_64
--->  Package gcc-c++.x86_64 0:4.8.5-4.el7 will be installed
.
.
.
Installed:
  gcc.x86_64 0:4.8.5-4.el7                                   gcc-c++.x86_64 0:4.8.5-4.el7                                           
  glibc-devel.x86_64 0:2.17-106.el7_2.6                      java-1.8.0-openjdk-devel.x86_64 1:1.8.0.101-3.b13.el7_2                
  ncurses-devel.x86_64 0:5.9-13.20130511.el7                 wxBase.x86_64 0:2.8.12-20.el7                                          

Dependency Installed:
  cpp.x86_64 0:4.8.5-4.el7          glibc-headers.x86_64 0:2.17-106.el7_2.6       kernel-headers.x86_64 0:3.10.0-327.22.2.el7      
  libmpc.x86_64 0:1.0.1-3.el7       libstdc++-devel.x86_64 0:4.8.5-4.el7         

Complete!

To Install Erlang

Download the erlang repository by using the following command.

[root@linuxhelp1 ~]# wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
--2016-07-22 10:49:58--  http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
Resolving packages.erlang-solutions.com (packages.erlang-solutions.com)... 31.172.186.53
Connecting to packages.erlang-solutions.com (packages.erlang-solutions.com)|31.172.186.53|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1932 (1.9K) [application/x-redhat-package-manager]
Saving to: ‘ erlang-solutions-1.0-1.noarch.rpm’ 

100%[==========================================================================================> ] 1,932       --.-K/s   in 0s      

2016-07-22 10:49:59 (68.4 MB/s) - ‘ erlang-solutions-1.0-1.noarch.rpm’  saved [1932/1932]
Now install the erlang repository
[root@linuxhelp1 ~]# rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:erlang-solutions-1.0-1           ################################# [100%]
--2016-07-22 10:50:11--  http://packages.erlang-solutions.com/rpm/centos/erlang_solutions.repo
Resolving packages.erlang-solutions.com (packages.erlang-solutions.com)... 31.172.186.53
Connecting to packages.erlang-solutions.com (packages.erlang-solutions.com)|31.172.186.53|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 245
Saving to: ‘ erlang_solutions.repo’ 

100%[==========================================================================================> ] 245         --.-K/s   in 0s      

2016-07-22 10:50:12 (15.7 MB/s) - ‘ erlang_solutions.repo’  saved [245/245]

Update the newly added repository

[root@linuxhelp1 ~]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: epel.mirror.net.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
erlang-solutions                                                                                                            613/613
Resolving Dependencies
-->  Running transaction check
--->  Package epel-release.noarch 0:7-6 will be updated
--->  Package epel-release.noarch 0:7-7 will be an update
.
.
.
Updated:
  epel-release.noarch 0:7-7                                                                                                         

Complete!

Run the following command to install the erlang package

[root@linuxhelp1 ~]# yum install erlang -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: epel.mirror.net.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Resolving Dependencies
-->  Running transaction check
--->  Package erlang.x86_64 0:19.0-1.el7.centos will be installed
-->  Processing Dependency: erlang-mnesia(x86-64) = 19.0-1.el7.centos for package: erlang-19.0-1.el7.centos.x86_64
-->  Processing Dependency: erlang-ic(x86-64) = 19.0-1.el7.centos for package: erlang-19.0-1.el7.centos.x86_64
-->  Processing Dependency: erlang-typer(x86-64) = 19.0-1.el7.centos for package: erlang-19.0-1.el7.centos.x86_64
.
.
.
                         
  erlang-orber.x86_64 0:19.0-1.el7.centos                          erlang-os_mon.x86_64 0:19.0-1.el7.centos                        
  erlang-otp_mibs.x86_64 0:19.0-1.el7.centos                       erlang-parsetools.x86_64 0:19.0-1.el7.centos                    
  erlang-percept.x86_64 0:19.0-1.el7.centos                        erlang-public_key.x86_64 0:19.0-1.el7.centos                    
  erlang-reltool.x86_64 0:19.0-1.el7.centos                        erlang-runtime_tools.x86_64 0:19.0-1.el7.centos                 
  erlang-sasl.x86_64 0:19.0-1.el7.centos                           erlang-snmp.x86_64 0:19.0-1.el7.centos                          
  erlang-ssh.x86_64 0:19.0-1.el7.centos                            erlang-ssl.x86_64 0:19.0-1.el7.centos                           
  erlang-stdlib.x86_64 0:19.0-1.el7.centos                         erlang-syntax_tools.x86_64 0:19.0-1.el7.centos                  
  erlang-tools.x86_64 0:19.0-1.el7.centos                          erlang-typer.x86_64 0:19.0-1.el7.centos                         
  erlang-wx.x86_64 0:19.0-1.el7.centos                             erlang-xmerl.x86_64 0:19.0-1.el7.centos                         
  tcl.x86_64 1:8.5.13-8.el7                                        tk.x86_64 1:8.5.13-6.el7                                        
  wxGTK.x86_64 0:2.8.12-20.el7                                     wxGTK-gl.x86_64 0:2.8.12-20.el7                                 

Complete!

To verify Erlang

Verify whether Erlang is installed or not by using the following command.

[root@linuxhelp1 ~]# erl
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.0  (abort with ^G)
1> 
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
^C[root@linuxhelp1 ~]#

To close the erlang shell, hit " Ctrl+C" twice.

Test a sample “ hello_world” program in Erlang.

Create a new file called “ hello.erl” in your favourite editor.

[root@linuxhelp1 ~]# vi hello.erl

Add the following lines.

-module(hello).
-export([hello_world/0]).
hello_world() ->  io:fwrite(" hello, world
" ).

Save and close the file.
Now open Erlang shell by using the following command.

[root@linuxhelp1 ~]# erl

Run the following commands one by one.
Add dot (.) at the end of each command.

[root@linuxhelp1 ~]# erl
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.0 (abort with ^G)
1>  c(hello).
{ok,hello}
2>  hello:hello_world().
hello, world
ok
3> 
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
^C[root@linuxhelp1 ~]#

To Install Elixir

Run the following command to install elixir.

[root@linuxhelp1 ~]# yum install elixir -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.fibergrid.in
* epel: mirror.rise.ph
* extras: mirror.fibergrid.in
* updates: mirror.fibergrid.in
Resolving Dependencies
-->  Running transaction check
--->  Package elixir.noarch 0:0.12.5-2.el7 will be installed
-->  Finished Dependency Resolution
.
.
.
Installed:
elixir.noarch 0:0.12.5-2.el7

Complete!

Export Elixir’ s bin PATH to your PATH environment by using the following command.

[root@linuxhelp1 ~]# export PATH=" $PATH:/root/elixir/bin" 

To verify Elixir

Verify Elixir by running the following command.

[root@linuxhelp1 ~]# iex
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

Interactive Elixir (0.12.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
^C[root@linuxhelp1 ~]#

To close the Elixir’ s shell, trigger Ctrl+C twice.
To know the version of elixir, run the following command.

[root@linuxhelp1 ~]# elixir --version
Elixir 0.12.5

FAQ
Q
Does anyone have a magic file for Erlang?
A
Magic files are used on unix systems with a tool called "file" to identify files. Here's an addition to /etc/magic which allows "file" to identify BEAM and JAM files.
Q
Where's List.append in Elixir?
A
Due to the underlying implementation of Elixir's lists, appending to a list is an O(n) operation. It's always much more efficient to prepend to the list and reverse the list. Prepending is O(1).
Q
How can I exit from erl console?
A
To exit the erl console
Press CTRL+C twice to get out from erl shell
Q
Why I am facing a Dependency issue How to resolve it?
A
You should try installing all necessary packages mentioned in above steps and check the firewall to work.
Q
What are the main problem domains Elixir is suitable for?
A
1)data processing
2)network related tasks: from plain sockets to web servers and frameworks
3)writing reliable, distributed, and highly available software.