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 -module(helloworld). -export([start/0]). 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!
Comments on this entry are closed.
This was nice, but it would’ve been better if you had explained what the lines are doing.
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.
Thank you