Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edeliver/Distillery fails with "bash: line 10: mix: command not found" error?

I get this error when I run mix edeliver build release production --verbose

A remote command failed on:
  [email protected]

But when I log into the server, Elixir (and thus Mix) seem to be installed fine.

ssh [email protected]
[email protected]:~$ mix -v
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

Mix 1.5.0

It seems to be working fine. What is Edeliver having trouble with finding my Elixir install? I used asdf version manager to install Elixir and Erlang.

like image 794
Mason Avatar asked Dec 08 '22 17:12

Mason


2 Answers

I added . $HOME/.asdf/asdf.sh at the bottom of my ~/.profile.

like image 61
Cade W. Avatar answered Jan 07 '23 05:01

Cade W.


Maybe asdf?

I have installed Elixir and Erlang using asdf and I had the same problem you do.

Apparently, asdf only executes in interactive mode, which means that if I connect via ssh to the server I can run it and use mix as usual, but if from a different machine I try to execute a command ( by not physically logging in and interacting with the terminal ) then it fails with the same error you have.

Possible solutions

There are two possible solutions to this issue:

  1. Install erlang and elixir natively as described in the original documentation.
  2. Change the .bashrc file

Instal Erlang and Elixir natively

The first solution, as proposed by @Gus, would technically work.However, you would be stuck with a specific erlang/elixir version in your machine, swapping between versions would be impossible and updates as well as fixes would not be available as quickly.

For me, someone who has several Elixir projects with different versions, this solution is a big "no-no".

Change the .bashrc file

The second solution is to manually edit your ~/.bashrc file. By default, unless you are logging in interactively (by hand) the system won't load mix, user environment vars and other things. To change this behaviour you can comment the following code ( or delete it )

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

This solution is dirty, but if you use it you get full access to everything, just as if you were accessing manually.

Problems

The issues with these solutions is that they don't use Edeliver, they simply use Distillery.

Another problem is that the second solution is quite hacky, so I am not sure it is a good practice (not to mention potential security implications).

Hope it helps!

like image 36
Flame_Phoenix Avatar answered Jan 07 '23 06:01

Flame_Phoenix