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!
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 2 comments… read them below or add one }
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.