My Adventures in Coding

February 11, 2009

Erlang – Getting Started and Using Eclipse

Filed under: Erlang — Brian @ 9:19 pm
Tags: , ,

Recently for fun I have been doing some recreational development in Erlang. I have put together a small set of notes here to help anyone else who is just getting started in Erlang, especially if you want to have some fun and use the Eclipse Erlang plugin!

Getting Started

Now when I was first starting to learn the language, I went through this tutorial: Introduction to Erlang. It walks you through the basic language structures such as Atoms, Tuples, and Lists. Also the final page of the tutorial shows you how to create a simple client and server for a chat room in Erlang. The amount of code required to write such an application is significantly shorter than what would be required to do the equivalent in Java or C#.

When I first started Erlang development I used Ubuntu Linux. The setup was very easy. Just open the Ubuntu software installer, search for “Erlang” and select install. That was all. Then to start the emulator all I had to do was type “erl” at a command prompt and that was it. It is important to note that the only folder the emulator will look in for MyProgram.erl files is in the folder from which the emulator was started.

NOTE: You can find a guide to all of the commands available in the Erlang shell at the official Erlang “Getting Started” tutorial.

Setup Eclipse and Erlang (On Windows)

I ran into a few snags while trying to do Erlang development in windows, so this is a quick document explaining how to do the proper setup with Eclipse. All of the instructions I found online left out a several important steps.

  1. Install Erlang, the windows binary can be obtained from  http://erlang.org/download.html
  2. Add the Erlang bin folder to your windows system path

    1. Control Panel -> System -> Advanced Settings ->  Environment Variables
    2. Under “System Variables” append PATH with the folder where Erlang was installed

      1. e.g.,  C:\Program Files\erl5.6.5\bin;
  3. Install Eclipse, any version will do, even the basic Java/Eclipse bundle
  4. Install the Erlang pluggin for Eclipse called “Erlide”

    1. Open Eclipse
    2. Help -> Software Updates -> Available Software
    3. Cick the button “Add Site” and enter the following URL

      1. http://erlide.sourceforge.net/update
      2. Click “OK”
    4. Now you should see the URL in the “Name” list under “Available Software”
    5. Expand the Erlide Update section and select “Stable builds”
    6. Now click the “Install” button in the upper right hand corner
    7. When the installation is finished restart Eclipse
  5. Now you will need to configure Eclipse to know the location of where Erlang was installed on your system

    1. Open Eclipse
    2. Window -> Preferences -> Erlang -> Installed Runtimes

      1. Click “Add” and select the path to the root Erlang install folder

        1. e.g., C:\Program Files\erl5.6.5\
      2. Click “OK”
      3. Restart Eclipse
  6. Now your setup should be complete

Creating an Erlang Project in Eclipse

There were a few little things that I missed when setting up a project that were not mentioned in any set of instructions I found. So here is a complete set of instructions to setup an Erlang project.

  1. File -> New -> Project
  2. Erlang -> Erlang Project
  3. Give the project a name e.g., “HelloWorld”
  4. Click “Next then click “Finish”
  5. Now, the project is created, but you won’t yet be able to compile
    1. Run -> Run Configurations
    2. Right click on “Erlang Application” and select “New”
    3. In the first tab titled “Main” select your project “HelloWorld”
    4. On the tab “Runtimes” ensure
      1. Runtime = Erlang
      2. Node name = erlide
    5. Now for the most important part, go to the “Environment” tab
      1. Click “Select”
      2. select “PATH”
      3. click “OK”
    6. Now click “Apply” and close the window
  6. You are now all setup!!!

Running an Erlang Project in Eclipse

One of the coolest things about developing Erlang code in Eclipse is that when you click “Run” it not only compiles all *.erl src files in the open Erlang project, but it also opens the Erlang emulator in “Console” where you can now type any command you want, run any function created in any of your *.erl projects and it will just work. No need to code in Eclipse then have to run your Erlang programs from the command prompt and no need to have to compile each *.erl file individually. Very slick!

From the Command Prompt

Now if all you want to do is use Erlang from the command prompt in windows, thats easy. Just open a command prompt and type “erl” and the emulator will open. Also you can just load the Erlang editor from the windows start menu (Start -> All Programs -> Erlang OTP – Erlang. The emulator works fine, however from here you will only be able to cut and paste code you want to run, you will not be able to open an existing erlang code file. To do this you will need to use the command prompt.

  1. So open a command prompt
  2. cd to the folder where the file is and type “erl”
    1. Now the emulator is open and you will have access to any files in the current directory.
  3. So now if you have the file “hello.erl” in that folder and want to execute this application
    1. c(hello). –This will compile the program
    2. hello:hello(). –This will execute the module “Hello” and function inside it also called “hello”

4 Comments »

  1. 4.3.1 http://erlide.org/update (has moved).

    Comment by Project Management Tools That Work (Bruce) — October 31, 2011 @ 3:38 pm | Reply

  2. […] 7. Y fin. Ya hemos creado nuestro programa “Helloworld” basado en Erlang, y empleando Eclipse como IDE.   Referencias: Wiki: http://es.wikibooks.org/wiki/Programaci%C3%B3n_en_Erlang Aprendiendo Erlang: http://aprendiendo-erlang.blogspot.com.es/2011/02/hola-mundo-i.html Plugin Erlide: https://myadventuresincoding.wordpress.com/2009/02/11/erlang-getting-started-and-using-eclipse/ […]

    Pingback by Erlang. Getting Started with Eclipse - El Blog de Rafael San Vidal — December 2, 2013 @ 4:23 am | Reply

  3. The erlide plug-in website Url has been changed to http://download.erlide.org/update.

    Comment by Ashish Gupta — June 14, 2014 @ 5:46 pm | Reply

  4. Enter http://download.erlide.org/update instead.

    Comment by Mathilda — January 20, 2016 @ 4:01 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: