Hello World in Elixir

Our first program will print the classic “hello world” message. Here’s the full source code.

defmodule HelloWorld do
  def main do
    IO.puts "hello world"
  end
end

HelloWorld.main()

To run the program, save the code in a file called hello_world.exs and use elixir to execute it.

$ elixir hello_world.exs
hello world

Elixir is a language focused on concurrent and functional programming. In Elixir, we define a module and a function. Here, we define a module HelloWorld and a function main that prints “hello world” to the console using IO.puts/1.

There is no direct equivalent of building binaries in Elixir like in some languages, but you can compile Elixir modules to bytecode and run them on the Erlang VM. For more advanced uses, you would typically create a self-contained release using tools like Mix and Distillery.

Now that we can run and build basic Elixir programs, let’s learn more about the language.