Elixir Basics

Get started with the basics of setting up Elixir.

Elixir version

For some examples, you’ll need to write commands in your terminal. They will look like this:

$ elixir -v

The command elixir -v goes after the $ sign. Type in the command and press “Enter” to see the result. This command will show the version of Elixir, confirming that it is installed.

A terminal is present below for you to test out the command.

Interactive shell

We will also work with some Elixir tools that use the terminal, especially in Chapter 7, Designing Your Elixir Applications. The main tool we will use in many examples is Elixir’s interactive shell, IEx. Launch the IEx by typing the following in the terminal.

$ iex

This interactive shell is very useful for quickly trying Elixir code and concepts, as well as for gathering information to debug local and remote systems. Type the code that runs inside the IEx shell after the iex> prompt and press “Enter” to see the result. For example,

iex> $ IO.puts "Hello, World!"

Inside IEx, we can press the “Tab” key to autocomplete. We can exit by pressing “Ctrl+C” twice.

Terminal 1
Terminal
Loading...

Hello-world program

Let us look at the simple hello-world program in Elixir.

/usercode/main.ex
IO.puts "Hello, World!"

We use the extension .exs for script files and .ex for compiled files. We can execute the code inside the file using the terminal, like this:

$ elixir main.ex

Press the “Run” button to execute the code.

IO.puts "Hello, World!"

That’s everything you need to know to use Elixir and run the examples in the course.

For this course, Elixir has already been set up on the Educative platform. If you wish to install Elixir on your local machines, follow the instructions in Appendix 1: Installing Elixir.