Add Path to Erlang Search Path?

David picture David · Aug 6, 2009 · Viewed 15.2k times · Source

I recently installed Erlang RFC4627 (JSON-RPC) with the debian package. I ran the test server using:

sudo erl -pa ebin

and then at the prompt:

test_jsonrpc:start_httpd().

returned

ok

I tested with http://:5671/ and got the success messages.

When I try to run rabbitmq-http2 however, I get the errors that the readme says are caused by rfc4627's code not being on the erlang search path. How do I put it on the path. I saw something on Dave Thomas's blog which suggested putting the path in the file:

~/.erlang

This didn't seem to work for me (maybe I did it wrong?).

Answer

Gordon Guthrie picture Gordon Guthrie · Aug 6, 2009

The code module is how you manipulate the path within an application.

The flags -pa that you used in starting the Erlang shell actually refer to a function in this module:

add_patha(Dir) -> true | {error, What}

You are right about the .erlang file in your home directory - it is run at start-up time of the shell and you can add in handy paths.

For an application you can start the shell with a batch file that calls something like this:

erl -pa ./ebin ../../lib/some/path/ebin

The flags behaviour of erl is described here.

For more sophisticated path management you need to get familiar with how OTP release management is done (but I suspect that is a while away for you yet).