Erlang will look for modules in the code path.
You can see the code path by invoking code:get_path()
:
4> code:get_path().
[".","/usr/lib/erlang/lib/kernel-3.0.3/ebin",
"/usr/lib/erlang/lib/stdlib-2.2/ebin",
"/usr/lib/erlang/lib/xmerl-1.3.7/ebin",
...
...
As you can see, the current directory is included, and probably everything else will be in some default system installation location. For me that means everything will be under '/usr/lib/erlang/lib' because that's where the library path is with Debian Linux, and the rest of the path 'APP-VERSION/ebin' is expanded from the library path (see below)...
The library path can be seen by invoking code:lib_dir()
:
5> code:lib_dir().
"/usr/lib/erlang/lib"
6>
The library path is expanded by finding everything under it that looks like an application, i.e. for every 'APP-VERSION/ebin' that exists under it, that's added to the code path. That's how the code path is generated. And the current directory is added of course.
The code module (worth a read) has various functions for changing the code path, and there are environment variables such as ERL_LIBS which allow you to add more paths, and the -pa argument to erl lets you add code paths as well.
Note that ERL_LIBS adds a lib, which will be searched for APP-VERSION/ebin occurrences, where as -pa adds a code path exactly as it is.
So, once you know all this, the simplest way of installing a module is...
- Copy the compiled beam file to the current directory.
OK! That is the easiest, but a slightly more advanced solution is probably appropriate...
- Create some directories under the library path (let's say 'my_app-1.0/ebin', so that would be '/usr/lib/erlang/lib/my_app-1.0/ebin' on my system), and copy your beam file to that.
Once that's done, start Erlang and it should add 'my_app-1.0/ebin' to the code path and any beam files in there should be found. They are installed.
Note that 'my_app-1.0' CAN be anything. It's convention only that says this should be the name of the app with a dash and the version. A useful convention though.
This is just installing a module, which was your question, but for completeness it's worth mentioning that installing an app can be done by copying the .app file to a code path location as well. It is that simple.
For beginners, isn't having module source in the current directory (and compiling them there) ok and not too difficult? And it's only a small step to copying files to the system location then. Generally third party applications you download and compile will generate an ebin directory with the app file and all the beam files in, so it's just a question of coping that ebin to my_app-version/ebin...