Starting with Elixir
Getting started with Elixir.
- Install Elixir
- Play in IEx to experiment.
- Execute a Script File.
- How to get started with the Elixir language.
- Where to Next?
Follow the installation steps for your platform on the official Elixir website.
I’m using Arch Linux, so that’s what I’ll do now.
Note: Installing Elixir will automatically install the Erlang dependency.
Wow, that was easy! At this point we can run IEx. Try it out.
Running Commands in the Interactive Shell (IEx)
Enter your first Elixir code with a “Hello World” example. Enter ‘IO.puts “Hello World”’.
Don’t worry about the “iex(2)” prompt. The number is showing the line number and it isn’t significant.
To exit the shell, enter CTRL+C two times.
Execute a Script File
The following create a module called “SayingHello” with a single function called “say_it”. After defining the module, we call the function.
Using your editor of choice, save this code to a file called “saying_hello.exs”.
Running this script file from the command line.
It runs immediately, performs the task and exits.
We can also copy and paste the module definition into IEx and play with it there.
Copy the following…
… paste it into IEx
Now at the prompt, type “Say” and press TAB. It will auto-complete to “SayingHello.”. Press “say” and TAB again to complete the rest. Hitting “enter” will execute the command.
Getting Started with the Language
This is enough to get an environment setup that run Elixir commands. Refer to the official documentation for learning about how the language works.
There are books available and websites for exercises to work on.
The Elixir website’s “Learning” section lists some of these resources.
- Programming Elixir - by Dave Thomas - The first Elixir book. An excellent resource.
- Elixir in Action - by Sasa Juric - I found this more approachable than Programming Elixir. Recommend it more for “Getting Started”. It assumes you have development experience.
- Elixir on exercism.io - Programming exercises in Elixir, with the benefit of community feedback.
- 30 days of Elixir - Github repo with code examples to play with. Not always the best solutions, but a nice source of stuff to work with.
Elixir is really cool. While IEx is awesome. It isn’t a great place to really play and dig into the language. Next we’ll cover getting started with an Elixir “mix”.