Unlimited WordPress themes, graphics, videos & courses! Unlimited asset downloads! From $16.50/m
Advertisement
  1. Code
  2. Elixir
Code

How to Install the Elixir Runtime

by
Difficulty:BeginnerLength:ShortLanguages:

Elixir is a meta-programming language based on Erlang and is available on all major operating systems. In this guide we will cover how to get Elixir installed, use the interactive console, and expand on the libraries available.

By the end of this guide you will be able to have a working development environment for creating Elixir apps. If you are interested in a framework for creating web apps, please look at using Phoenix.

Getting Elixir

The easiest and preferred way to install Elixir is via a distribution, or by using an installer. 

Erlang 18.0 or later is used by Elixir and will be installed by default by the distribution installer.

Precompiled Packages

If you wish to install from source or a precompiled package, Erlang will need to be installed separately; for that, please check this guide.

MacOS

  • Homebrew
    • Update your homebrew to latest: brew update
    • Run: brew install elixir
  • Macports
    • Run: sudo port install elixir

Unix (and Unix-like)

  • Arch Linux (Community repo)
    • Run: pacman -S elixir
  • openSUSE (and SLES 11 SP3+)
    • Add Erlang devel repo: zypper ar -f http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_Factory/ erlang
    • Run: zypper in elixir
  • Gentoo
    • Run: emerge --ask dev-lang/elixir
  • GNU Guix
    • Run: guix package -i elixir
  • Fedora 21 (and older)
    • Run: yum install elixir
  • Fedora 22 (and newer)
    • Run dnf install elixir
  • FreeBSD
    • From ports: cd /usr/ports/lang/elixir && make install clean
    • From pkg: pkg install elixir
  • Ubuntu 12.04/14.04/16.04 or Debian 7
    • Add Erlang Solutions repo: wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
    • Run: sudo apt-get update
    • Install the Erlang/OTP platform and all of its applications: sudo apt-get install esl-erlang
    • Install Elixir: sudo apt-get install elixir

Windows

Docker

For ease of portability, you can also use the official elixir docker image. This is easy to work with just by running one of the following commands:

  • Enter interactive mode
    • Run: docker run -it --rm elixir
  • Enter bash within container with installed elixir
    • Run: docker run -it --rm elixir bash

Installing From Git

Ensure you have Erlang installed first by visiting the Erlang download page and getting a distribution for your Operating System.

Choose a Erlang distribution for your OS

Once Erlang is installed on your machine, please use the following commands:

Testing Your Installation

Once you have installed Elixir, please run the following at your terminal prompt:

If you are getting an error, please ensure the binary is in your PATH environmental variable.

Windows users can read this guide.

Interactive Development

Akin to other languages such as Node, Ruby, and Java, Elixir has an interactive mode, which we can access via the command-line prompt as so:

Windows users will need to run iex.bat to access the interactive console. 

When we enter this mode, we can type any Elixir code and get the return instantly, so it's good for starting to learn the language.

Let's do some basic expressions:

When we are running a script, we do that from the shell terminal as so:

Setting Up Your IDE

Setting Up Your IDE

If you are using JetBrains' IntelliJ, Sublime or Atom then you will be happy to know there are several integration plugins available which will make code completion, syntax highlighting, linting your code and displaying errors and warnings easy.

Vim Users

If you are using Vim or Emacs, then you can configure support for Elixir such as automatic filetype detection, syntax highlighting and automatic indentation. 

Installation can be done with a Vim plugin manager such as pathogen.vim inside ~/.vim/bundle:

Adding Packages With Hex

Take full advantage of the thousands of packages available for the Elixir ecosystem via Hex.pm.

Search for packages and install them via the mix dependency manager—usage on how to setup mix is in the documentation. Once you have a mix.exs set up, adding this line would install the popular JSON library poison:

{:poison, "~> 3.1"}

There are many packages ready for your use on Hex which can provide a plethora of solutions such as JSON and XML support, SSL cryptography functions, database abstraction and caching, to name a few.

Adding Packages With Hex

If you are looking for powerful packages, as mentioned before, check out Poison, a very fast pure Elixir JSON library!

Also worth checking is hackney, a simple HTTP client, and plug, a specification for composable web modules which can easily port between your applications and save you a lot of time.

Conclusion

Elixir is easily available via all of the distribution channels accessible and some rather exotic ones also, such as Raspberry Pi. Installing from source is easy, as is using a package manager such as the popular brew on macOS.

Going forward, you may wish to review the Erlang libraries available for Elixir, and also, as mentioned earlier, get further into taking advantage of using Hex packages.

If you are looking for some excellent packages that expand Elixir then you will enjoy this curated list on GitHub.

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.