I checked out rebar, but that seems way too complex. Maybe someone could post something that says, %Post your code here in the following rebar app
Here's what I ended up doing:
Install rebar3:
$ git clone https://github.com/rebar/rebar3.git $ cd rebar3 .../rebar3$ ./bootstrapAnd now you have the script rebar3 and can copy it to somewhere in your $PATH as described in the previous section.
Or, you can download the .zip file, unzip it, then change into the rebar3 directory and issue the ./bootstrap command.
That creates the executable rebar3 inside the /rebar3 directory. I moved the rebar3 executable into /usr/local/bin, which is a directory listed in my PATH environment variable (various possible PATH locations are discussed here):
.../rebar3$ sudo mv rebar3 /usr/local/bin
That allows me to use the rebar3 command at any prompt. As an alternative, after you create your app(see the next step) you can copy rebar3 into your app's directory and from that directory issue rebar commands like this:
$ ./rebar3 .....
Then I created a new app:
~/erlang_programs$ rebar3 new app myapp
(Substitute your app name in place of: myapp)
Then:
~/erlang_programs$ cd myapp
~/erlang_programs/myapp$
In order to use jsx, a third party JSON library, I added jsx as a dependency:
Dependencies are listed in
rebar.configfile under the deps key:{erl_opts, [debug_info]}. {deps, [ {jsx, "2.8.0"} ]}.
rebar.config resides here:
~/erlang_programs/myapp$ ls
LICENSE _build rebar.lock
README.md rebar.config src
Then I added my erlang program to the myapp/src directory:
my_app/src/my.erl:
-module(my).
-export([test/0]).
test() ->
jsx:decode(<<"{\"data\": [1, 2, 3]}">>).
Finally:
~/erlang_programs/myapp$ rebar3 shell
===> Verifying dependencies...
===> Fetching jsx ({pkg,<<"jsx">>,<<"2.8.0">>})
===> Version cached at /Users/7stud/.cache/rebar3/hex/default/packages/jsx-2.8.0.tar is up to date, reusing it
===> Compiling jsx
===> Compiling myapp
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V6.4 (abort with ^G)
1> my:test().
[{<<"data">>,[1,2,3]}]
If you make changes to your .erl file, in my case the file my.erl, you don't need to exit the shell--just compile as usual, e.g. c(my).