Programming Languages Section

Go for A Ride with Elixir

Card image
Post by Amina Delali, November 22th,2021

Some Facts

Elixir is a functional, dynamically typed, and a concurrent programming language. It is built upon the Erlang language, and it also compiles down to Erlang bytecode. It's characterized by a Ruby-like syntax: simple and modern. It also allows you to build fault tolerant and scalable applications. The language is perfect for building networked and web applications. For instance, the language is used by Adobe for their collaborative photography workflow, and by Discord for their messaging system.



How to install it

  • on Windows:

    To install Elixir on Windows 10, just download the installer that you can find in the official installation page of the language in the windows section. Then run the installer and follow the on screen displayed instructions.

  • on ubuntu : Just follow these steps:
    1. add this line "deb <https://packages.erlang-solutions.com/ubuntu> trusty contrib" at the end of the file "/etc/apt/sources.list" , in order to add a new repository entry .
      You can open and edit the file using this command (you must have nano already installed in your system):  sudo nano /etc/apt/sources.list
    2. get and add the corresponding public key using these commands:  wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc
      sudo apt-key add erlang_solutions.asc
    3. Then run the following commands:  sudo apt update 
      sudo apt install esl-erlang
      sudo apt install elixir
    4. check the installed version by the following command:  elixir --version

The Hello World Example

    There are 2 modes in which you can run Elixir code: scripted mode and compiled mode:

    Scripted mode: just do the following

    1. create a new file in the home directory and name it : hello.exs
    2. write and save the following code in the hello.exs file: 
      IO.puts("Hello World!")
    3. open the terminal from the home directory and run the following command:  elixir hello.exs

    Compiled mode: just follow the described steps below:

    1. create a new file in the home directory and name it: start.ex
    2. write and save the following code in the start.ex file: 
      defmodule Start do
          def sayHello() do
              IO.puts("Hello World!")
          end
      end
    3. open the terminal from the home directory and compile the code with the following command:  elixirc start.ex
    4. launch the Elixir's interactive shell with the following command: iex
    5. on the shell, write the following command and hit enter:  Start.sayHello()


Something to say ?

If you want to add something about the language or about this post, please feel free to do it by commenting below 🙂 .