01 January 2010 ~ 5 Comments

Installing Erlang on Snow Leopard

Here’s another in my series of “Installing X on Snow Leopard”. These aren’t official, well-tested guides; they’re just documentations of my attempts to compile and install various things on my personal computer. My last one (Installing MySQL on Snow Leopard) is my most popular post to date (aside from a couple that have been on Reddit). Erlang is less popular than MySQL, but hopefully this will still help a few people.

Downloading and unpacking

Go to http://erlang.org/download.html and download the Source for the newest version (when I was writing this, that was R13B03. After downloading, extract it to somewhere that’s convenient to get to with the Terminal.

Configure

Open the Terminal and cd into the directory you extracted Erlang to (mine was /Users/jake/src/otp_src_R13B03 . Then run the following command:

./configure \
--prefix=/usr/local/ \
--enable-smp-support \
--enable-threads \
--enable-darwin-64bit

Note: You will probably get three errors. Read about them in the Configuration Errors section coming up.

The first three configure options are the defaults according to the README. However, I’ve had experiences where supposed defaults aren’t really the defaults when compiled on OS X, so I don’t like to take chances. --enable-darwin-64bit enables experimental support for the 64bit x86 Darwin binaries. This may not be necessary, but in general, 64-bit stuff has fewer problems on Snow Leopard, so I figured this was a good idea.

Configuration Errors

I got the following configuration errors:

jinterface    : No Java compiler found
wx            : Can not combine 64bits erlang with wxWidgets on
                MacOSX, wx will not be useable
documentation : fop is missing. The documentation can not be built.

These aren’t a problem. If you get any errors besides these, you’re in trouble. Leave a comment, and I’ll see if I can help.

Making and installing

These two commands shouldn’t give you any trouble:

make

And then, after make is done:

sudo make install

If you get any errors at either of these stages, leave a comment and I’ll try to help.

Making sure it works

Note: This canonical test is gratefully borrowed from erlang.org.

Put the following into a text file:

-module(test).
-export([fac/1]).

fac(0) -> 1;
fac(N) -> N * fac(N-1).

Save it as test.erl in a directory that’s easy to get to with the Terminal. Then, from the Terminal, cd into that directory and type erl (which, if everything worked right, should start the Erlang command-line interpreter). From the interpreter, run the following commands:

1> c(test).
{ok,test}
2> test:fac(20).
2432902008176640000
3> test:fac(40).
815915283247897734345611269596115894272000000000

Note: Lines starting with N> (where N is a number) are lines you should type (but just type the stuff coming after N>). The other lines represent output.

c(test). compiles test.erl (assuming it’s in the directory you cd‘ed into). test:fac(20). and test:fac(40). runs your factorial function.

So, that’s what worked for me. If anyone has any problems along the way, leave a comment and I’ll try to help.

5 Responses to “Installing Erlang on Snow Leopard”

  1. Tobin 11 January 2010 at 10:15 am Permalink

    Worked perfectly, very helpful. Thank you.

  2. mmochan 24 February 2010 at 1:10 am Permalink

    I’ve just installed erlang on snow leopard so I’m guessing this a user error on my behalf but would be grateful if you could point me in the right direction.

    I’m getting the following error when trying to compile test.erl

    module(test).
    -export([fac/1]).

    fac(0) -> 1;
    fac(N) -> N * fac(N-1).

    Erlang R13B03 (erts-5.7.4) [/source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

    Eshell V5.7.4 (abort with ^G)
    1> c(test).
    ./test.erl:1: syntax error before: ‘.’
    ./test.erl:2: no module definition
    error
    2> 123123*121132.
    14914135236
    3>

    Thanks

    Mike

  3. Jake Boxer 24 February 2010 at 7:07 am Permalink

    mmochan:

    If the source you pasted in here is accurate, you’re missing a dash (‘-’) at the beginning of your first line (right next to the ‘m’ in “module”). Let me know if adding the dash fixes it, or if not, what error message you’re getting.

  4. mmochan 24 February 2010 at 7:22 am Permalink

    Thanks Jake all working now


Leave a Reply