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!
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.
- Install Erlang, the windows binary can be obtained from http://erlang.org/download.html
Add the Erlang bin folder to your windows system path
- Control Panel -> System -> Advanced Settings -> Environment Variables
Under “System Variables” append PATH with the folder where Erlang was installed
- e.g., C:\Program Files\erl5.6.5\bin;
- Install Eclipse, any version will do, even the basic Java/Eclipse bundle
Install the Erlang pluggin for Eclipse called “Erlide”
- Open Eclipse
- Help -> Software Updates -> Available Software
Cick the button “Add Site” and enter the following URL
- Click “OK”
- Now you should see the URL in the “Name” list under “Available Software”
- Expand the Erlide Update section and select “Stable builds”
- Now click the “Install” button in the upper right hand corner
- When the installation is finished restart Eclipse
Now you will need to configure Eclipse to know the location of where Erlang was installed on your system
- Open Eclipse
Window -> Preferences -> Erlang -> Installed Runtimes
Click “Add” and select the path to the root Erlang install folder
- e.g., C:\Program Files\erl5.6.5\
- Click “OK”
- Restart Eclipse
- Click “Add” and select the path to the root Erlang install folder
- 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.
- File -> New -> Project
- Erlang -> Erlang Project
- Give the project a name e.g., “HelloWorld”
- Click “Next then click “Finish”
- Now, the project is created, but you won’t yet be able to compile
- Run -> Run Configurations
- Right click on “Erlang Application” and select “New”
- In the first tab titled “Main” select your project “HelloWorld”
- On the tab “Runtimes” ensure
- Runtime = Erlang
- Node name = erlide
- Now for the most important part, go to the “Environment” tab
- Click “Select”
- select “PATH”
- click “OK”
- Now click “Apply” and close the window
- 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.
- So open a command prompt
- cd to the folder where the file is and type “erl”
- Now the emulator is open and you will have access to any files in the current directory.
- So now if you have the file “hello.erl” in that folder and want to execute this application
- c(hello). –This will compile the program
- hello:hello(). –This will execute the module “Hello” and function inside it also called “hello”