Cannot use command line Elixir mix (macOS High Sierra) - erlang

When i run command elixir -v or mix, it will return:
{"init terminating in do_boot",{undef,[{elixir,start_cli,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
Crash dump is being written to: erl_crash.dump...done
init terminating in do_boot ()
Some details:
$ brew list
elixir erlang ...
$ erl
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.0 (abort with ^G)
1>
$ elixir
Usage: elixir [options] [.exs file] [data]
-e COMMAND Evaluates the given command (*)
-r FILE Requires the given files/patterns (*)
...
I have used brew uninstall, reinstall, but nothing change. Please help me fix it!

erl without any arguments will run Erlang shell. But if you want to run Elixir shell you should try running iex (interactive elixir). elixir is used to run programs you already coded, like elixir simple.exs
Or it might be that your Erlang version is little out of date. Try running brew update.

Related

cannot start empty OTP application from command line

I have created an OTP application skeleton with rebar:
$ rebar create-app appid=test
then I compiled it with rebar compile, and when I run
$ erl -pa ebin -s test
I get this error
{"init terminating in do_boot",{undef,[{test,start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
but if I call start from the shell it works:
$ erl -pa ebin
Erlang R15B01 (erts-5.9.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.1 (abort with ^G)
1> application:start(test).
ok
How can I start the application from the OS command line?
EDIT:
I figured that I needed to run
$ erl -pa ebin -s application start test
now I am not getting any errors, but the app is still not getting started...
erl -pa ebin/ -eval "application:start(test)"
Since the start function in test_app.erl has arity 2 it is not possible to invoke it directly using the erl switch -s (or -run), only arity 0 or 1 are possible to invoke with those switches (see http://erlang.org/doc/man/erl.html).
You could add a wrapper function that in turn calls the start/2, but I think the -eval is more elegant.
The -s flag assumes a list of arguments when one or more arguments are presented. So what $ erl -pa ebin -s application start test would do is calling application:start([test]) which would not work as expected.
Here is a workaround (might not be the best solution):
Create a source file src/test_init.erl with the following content:
-module(test_init).
-compile(export_all).
init() ->
application:start(test).
Then:
$ rebar compile
$ erl -pa ebin -s test_init init
Now the test application should be running:)

rebar generate: enotdir errors

I am trying to setup a rebar release for my otp application. I followed this guide: https://github.com/basho/rebar/wiki/Getting-started
When I try to generate a release, I get lots of enotdir errors:
~/Projekte/mc-erl/repo $ ./rebar generate
==> rel (generate)
Error reading /home/clonejo/Projekte/mc-erl/repo/rebar/rebar_app_utils.beam's file info: enotdir
Error reading /home/clonejo/Projekte/mc-erl/repo/rebar/rebar_deps.beam's file info: enotdir
Error reading /home/clonejo/Projekte/mc-erl/repo/rebar/rebar_appups.beam's file info: enotdir
[... enotdir errors go on ...]
[... all above enotdir errors are repeated ...]
ERROR: Unable to generate spec: read file info /usr/lib/erlang/man/man1/preunzip.1 failed
This is my version of erlang:
$ erl
Erlang R15B (erts-5.9) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9 (abort with ^G)
I got rebar at http://cloud.github.com/downloads/basho/rebar/rebar (see the GettingStarted wiki page).
Update: Verbose mode only adds one warning, which is unrelated:
WARN: 'generate' command does not apply to directory /home/clonejo/Projekte/mc-erl/repo/apps/mc_erl
Most likely, you have installed the "reloader" module somehow, perhaps via your .erlang? That specific error message originates from there.
Could you run it with -v
There was and maybe still is a bug
http://lists.basho.com/pipermail/rebar_lists.basho.com/2011-July/000932.html
I would suggest to update rebar and run rebar -v to see more info.

start common node in erlang shell

Facing problem with slave:start/2 in lion OS, so I have to try another direction "start common node with os:cmd automatically" in erlang shell.
One way is by command directly, and another way is through bash file. But both way faces the same problem. If can't start automatically, I have to start node manually everytime.
Eshell V5.9 (abort with ^G)
(emacs#yus-iMac.local)1> os:cmd("erl -name abcd").
"Eshell V5.9 (abort with ^G)\n(abcd#yus-iMac.local)1> *** Terminating erlang ('abcd#yus-iMac.local')\n"
(emacs#yus-iMac.local)3> os:cmd("~/Documents/Project/node_start").
"Eshell V5.9 (abort with ^G)\n(abc#yus-iMac.local)1> *** Terminating erlang ('abc#yus-iMac.local')\n"
The bash file content is as follows:
#/bin/sh
erl -name abc
Not that I'm really fond of this approach, but to make the above work you should pass the "detached" parameter to the 'erl' command:
erl -name foo
1> os:cmd("erl -name bar -detached").
[]
2> net_adm:ping('bar#pigeon.local').
pong
3> nodes().
['bar#pigeon.local']
Reading from the doc:
-detached
Starts the Erlang runtime system detached from the system console. Useful for running daemons and backgrounds processes. Implies
-noinput.

Erlang. Start remote shell error

I tried to start remote shell and get a following error:
*** ERROR: Shell process terminated! (^G to start new job) ***
Details:
1. Start erlang on a computer a2-x201:
erl -sname a#a2-x201
Erlang R14B (erts-5.8.1) [source] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.8.1 (abort with ^G)
(a#a2-x201)1> nodes().
[]
Start erlang on a computer a2-asrock
erl -sname b#a2-asrock
Establish link between nodes using computer a2-x201:
(a#a2-x201)2> net_adm:ping('b#a2-asrock').
pong
(a#a2-x201)3> nodes().
['b#a2-asrock']
Everything looks ok at the moment.
Starting remote shell on a2-asrock from a2-x201
CTRL+ G
-->r 'b2#a2-asrock'
-->j
1 {shell,start,[init]}
2* {'b2#a2-asrock',shell,start,[]}
-->c
* ERROR: Shell process terminated! (^G to start new job) *
What is wrong?
You are doing remoting on 'b2#a2-asrock' instead of 'b#a2-rock' which is the name of the created node. You're pinging 'b#a2-asrock' but you're trying to connect to 'b2#a2-asrock' instead. Seems that you have a typo in there.

rebar: error exit on create-app: {crypto,start,[]}

I followed the instructions here, to the letter. I then ran the instruction to create an application project structure, and got the following error.
$ ./rebar create-app appid=myapp
Uncaught error in rebar_core: {'EXIT',
{undef,
[{crypto,start,[]},
{rebar_core,run,1},
{rebar,main,1},
{escript,run,2},
{escript,start,1},
{init,start_it,1},
{init,start_em,1}]}}
Any ideas what I'm doing wrong?
It looks like your Erlang was compiled without OpenSSL (the crypto module). crypto is required for many (most?) Erlang applications. You'll need to get a version of Erlang with a working crypto module, and then you shouldn't have any problems like this.
A clarification to YOUR ARGUMENT IS VALID's answer (adding as an answer because the comment is too short).
It may be that Erlang was compiled properly but the OpenSSL libraries are not visible to Erlang, so the crypto server can't be started. I compiled Erlang on Solaris 10 and it didn't complain about OpenSSL not being installed. In fact, it compiled crypto and installed it in: /usr/local/lib/erlang/lib/crypto-2.2/
But Rebar still wasn't working. It's easy to check if the problem is indeed with the crypto module.
Open Erlang shell and type crypto:start(). This was happening on my system:
bash-3.2# erl
Erlang R15B03 (erts-5.9.3.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3.1 (abort with ^G)
1> crypto:start().
** exception error: undefined function crypto:start/0
2>
=ERROR REPORT==== 8-Feb-2013::15:28:43 ===
Unable to load crypto library. Failed with error:
"load_failed, Failed to load NIF library: 'ld.so.1: beam.smp: fatal: relocation error: file /usr/local/lib/erlang/lib/crypto-2.2/priv/lib/crypto.so: symbol DES_ede3_cfb_encrypt: referenced symbol not found'"
OpenSSL might not be installed on this system.
=ERROR REPORT==== 8-Feb-2013::15:28:43 ===
The on_load function for module crypto returned {error,
{load_failed,
"Failed to load NIF library: 'ld.so.1: beam.smp: fatal: relocation error: file /usr/local/lib/erlang/lib/crypto-2.2/priv/lib/crypto.so: symbol DES_ede3_cfb_encrypt: referenced symbol not found'"}}
If OpenSSL is installed in a non-standard location, as it is the case when using OpenCSW to install OpenSSL on Solaris 10, it is easy to fix the problem by adding the library path to the environment variable. For example on Solaris 10 to /etc/profile:
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/csw/lib
export LD_LIBRARY_PATH
Then log-out and log-in or re-load the bash environment, for example like this:
bash-3.2# . /etc/profile
Result:
bash-3.2# erl
Erlang R15B03 (erts-5.9.3.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3.1 (abort with ^G)
1> crypto:start().
ok
I'd recommend using precompiled Erlang which is available from Erlang Solutions: https://www.erlang-solutions.com/downloads/download-erlang-otp
There's one for Windows too.
Getting this error when running make command:
root#hs:/var/www/html/ejabberd-master# make
rm -rf deps/.got
rm -rf deps/.built
/usr/local/lib/erlang/bin/escript rebar get-deps && :> deps/.got
Uncaught error in rebar_core: {'EXIT',
{undef,
[{crypto,start,[],[]},
{rebar,run_aux,2,
[{file,"src/rebar.erl"},{line,163}]},
{rebar,main,1,
[{file,"src/rebar.erl"},{line,58}]},
{escript,run,2,
[{file,"escript.erl"},{line,757}]},
{escript,start,1,
[{file,"escript.erl"},{line,277}]},
{init,start_it,1,[]},
{init,start_em,1,[]}]}}
make: *** [deps/.got] Error 1
The erlang details are:
root#hs:/home/node# erl
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async- threads:10] [hipe] [kernel-poll:false]
Eshell V7.0 (abort with ^G)
1> crypto:start()
1>
Seems like crypto not working, as the command gives "Ok" or "exception error".
Help needed.
Thanks for the answer Ivan. But it seems I figured out the issue:
The ubuntu auto updates were turned off and the dependencies were not installed while compiling erlang (e.g. libssh-dev). Once the auto update was turned on it compiled and make command ran fine.

Resources