In this tutorial, we are going to teach you about Elixir fundamentals - the language syntax, how to define modules, how to manipulate the characteristics of common data structures, and more. This chapter will focus on ensuring that Elixir is installed and that you can successfully run Elixir’s Interactive Shell, called IEx.
Our requirements are (see
Let’s get started!
If you find any errors in the tutorial or on the website, please report a bug or send a pull request to our issue tracker.
The Elixir guides are also available in EPUB format:
If you haven’t yet installed Elixir, visit our installation page. Once you are done, you can run
elixir --version to get the current Elixir version.
When you install Elixir, you will have three new executables:
elixirc. If you compiled Elixir from source or are using a packaged version, you can find these inside the
For now, let’s start by running
iex.bat if you are on Windows PowerShell, where
iex is a PowerShell command) which stands for Interactive Elixir. In interactive mode, we can type any Elixir expression and get its result. Let’s warm up with some basic expressions.
iex and type the following expressions:
Erlang/OTP 21.0 [64-bit] [smp:2:2] [...] Interactive Elixir (1.11.2) - press Ctrl+C to exit iex(1)> 40 + 2 42 iex(2)> "hello" <> " world" "hello world"
Please note that some details like version numbers may differ a bit in your session; that’s not important. From now on
iex sessions will be stripped down to focus on the code. To exit
It seems we are ready to go! We will use the interactive shell quite a lot in the next chapters to get a bit more familiar with the language constructs and basic types, starting in the next chapter.
Note: if you are on Windows, you can also try
iex.bat --werlon PowerShell) which may provide a better experience depending on which console you are using.
After getting familiar with the basics of the language you may want to try writing simple programs. This can be accomplished by putting the following Elixir code into a file:
IO.puts "Hello world from Elixir"
Save it as
simple.exs and execute it with
$ elixir simple.exs Hello world from Elixir
When going through this getting started guide, it is common to have questions; after all, that is part of the learning process! There are many places where you can ask questions, here are some of them:
When asking questions, remember these two tips:
Instead of asking “how to do X in Elixir”, ask “how to solve Y in Elixir”. In other words, don’t ask how to implement a particular solution, instead describe the problem at hand. Stating the problem gives more context and less bias for a correct answer.
In case things are not working as expected, please include as much information as you can in your report, for example: your Elixir version, the code snippet and the error message alongside the error stacktrace. Use sites like Gist to paste this information.
© 2012 Plataformatec
Licensed under the Apache License, Version 2.0.