View Source Introduction
This guide will teach you about Elixir fundamentals - the language syntax, how to define modules, the common data structures in the language, and more. This chapter will focus on ensuring that Elixir is installed and that you can successfully run Elixir's Interactive Shell, called IEx.
Let's get started.
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. The requirements for this guide are:
- Elixir 1.15.0 onwards
- Erlang/OTP 26 onwards
If you are looking for other resources for learning Elixir, you can also consult the learning page of the official website.
When you install Elixir, you will have three new command line executables:
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 26 [64-bit] [smp:2:2] [...]
Interactive Elixir - press Ctrl+C to exit
iex(1)> 40 + 2
iex(2)> "hello" <> " world"
Please note that some details like version numbers may differ a bit in your session, that's not important. By executing the code above, you should evaluate expressions and see their results. 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 and running on an Erlang/OTP version earlier than 26, 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
Later on we will learn how to compile Elixir code and how to create and work within Elixir projects using the Mix build tool. For now, let's move on to learn the basic data types in the language.