Erlang Hello World Example: How To Write, Compile and Execute Erlang Program on Linux OS

by SathiyaMoorthy on May 21, 2010

Question: I would like to understand the basics of how to write and execute Erlang program on Linux OS. Can you explain it with a simple example?

Answer: In this article, let us review very quickly how to write a basic Hello World Erlang program, Compile and execute erlang program on Linux or Unix OS.

If you are new to Erlang programming language, read this erlang programming page on wikipedia.

1. Write a Hello World Erlang Program

Create the helloworld program using a Vim editor as shown below.

$ vim helloworld.erl

% hello world program

start() ->
    io:fwrite("Hello, world!\n").

Note: Comment in Erlang starts with %.

2. Make sure Erlang command line interpreter is installed on your system

Make sure Erlang compiler is installed on your system as shown below.

$ whereis erlc
erlc: /usr/bin/erlc /usr/share/man/man1/erlc.1.gz

Installing erlang Compiler

If you don’t have erlang compiler, install it as shown below.

$ sudo apt-get install erlang-ic

3. Compile the erlang program

Compile the erlang hello world which will create the executable.

$ erlc helloworld.erl

$ ls
helloworld.beam  helloworld.erl 

4. Execute the erlang Program

Execute as shown below.

$ erl -noshell -s helloworld start -s init stop
Hello, world!

5. Erlang one liner

You can also execute erlang from the command line as shown below. This will print Hello World!.

$ erl -noshell -eval 'io:fwrite("Hello, World!\n"), init:stop().'
Hello, World!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 2 comments… read them below or add one }

1 Greg Bair May 21, 2010 at 6:16 am

This was nice, but it would’ve been better if you had explained what the lines are doing.

2 My Name is Erl November 3, 2011 at 7:29 pm

Thanks for this (even if you use vim).

Interestingly, I made crucial error of naming file something other than what is in the “module” parentheses, good grief, the error file generated is massive.

Leave a Comment

Previous post:

Next post: