Getting Erlang up and running on your Mac
Howto install and get Erlang up and running on Mac OS (Lion) in minutes
Today I set out to get Erlang installed and working on my new MacBook Pro running Mac OS X Lion.
My objectives:
- Installing Erlang
- Installing Erlang mode in Aquamacs (Emacs)
- Running Hello World written in Erlang from Aquamacs
I started out by trying out different package managers – first out was MacPorts (http://www.macports.org/). But Erlang din’t want to compile with gcc (and lots of people seem to have this problem on Lion). Tried switching from gcc 4.2 to gcc 4.5, but somewhere along here I just got tired and reverted (uninstalled) all my installed ports using:
port -fp uninstall --follow-dependents installed
I decided to switch to Homebrew which is another popular package manager. You can find and install it from http://mxcl.github.com/homebrew/.
Now time to install Erlang!
brew install erlang
Done! And a lot easier in my opinion.
Previously I had already installed Aquamacs (which is a nice Mac OS alternative if you are into using Emacs as your IDE). Now I just wanted to get the Emacs mode supplied with Erlang working.
Let’s install the Emacs mode in Aquamacs.
First you have to locate the Aquamacs Preferences.el file. It should be located under:
~/Library/Preferences/Aquamacs Emacs
Add the following lines to Preferences.el:
;; Erlang mode (installed via Homebrew)
(setq load-path (cons"/usr/local/Cellar/erlang/R14B04/lib/erlang/lib/tools-2.6.6.5/emacs" load-path))
(setq erlang-root-dir "/usr/local/Cellar/erlang/R14B04/lib/erlang/lib")
(setq exec-path (cons "/usr/local/Cellar/erlang/R14B04/lib/erlang/bin" exec-path))
(require 'erlang-start)
Please note that the the paths above might differ on your computer depending on how you installed Erlang (if you used Homebrew or not) or what Erlang version you are using. If your paths are different, just update the lines above to match your paths!
Now, let’s start up Aquamacs and get that Hello World running!
Create a new file called hello.erl in Aquamacs. If things are working correctly, this should activate the Erlang mode in Aquamacs (Emacs). You should also see a new “Erlang” menu (next to Tools) in the main menu bar in Aquamacs.
Let’s write a simple Hello World in Erlang (see http://www.erlang.org/faq/getting_started.html).
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("hello, world\n").
And now finally, let’s run it from within Aquamacs.
Hit Ctrl-C Ctrl-K (or select Erlang -> Compile -> Compile Buffer in the menu).
A new buffer window should now open in Aquamacs containing the Elang interpreter.
Run the Hello World function by entering the following (in the Elang buffer window):
hello_world().
If all is well, Erlang will return:
hello, world
ok
Objectives completed!
[To exit the Erlang interpreter call "init:stop()." and hit "Ctrl-X K Enter" and then "Ctrl-0" (zero) in Aquamacs.]
The screenshot below shows the expected output when running Hello World in Aquamacs.





