asdf-elixir: Running `iex -S mix phx.server` fails

Running iex -S mix phx.server fails:

$ iex -S mix phx.server
Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]

** (SyntaxError) /home/jarmo/.asdf/shims/mix:3:18: syntax error before: '.'
    (elixir 1.11.2) lib/code.ex:931: Code.require_file/2

Running mix phx.server seems to work without any issues.

Erlang and Elixir are system installations on Ubuntu 16.04.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 33 (9 by maintainers)

Most upvoted comments

@Stratus3D

But in any case if you follow the instructions in the asdf docs you should have a working setup.

I’m pretty sure that I followed asdf instructions in the doc and did the same when installing Elixir/Erlang long before installing asdf. I don’t think that I have done anything to steer off the path of “official” way of installing/loading either of these.

I have created two Dockerfiles to reproduce this problem.

First is a Docker file, which uses only system installation to show that it works as expected:

# Dockerfile.system

FROM ubuntu

ARG DEBIAN_FRONTEND=noninteractive

RUN apt update -y
RUN apt upgrade -y
RUN apt install -y wget

# System installation of Erlang and Elixir according to https://elixir-lang.org/install.html
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && apt install -y --fix-broken ./erlang-solutions_2.0_all.deb
RUN apt update -y
RUN apt install -y esl-erlang
RUN apt install -y elixir

WORKDIR /home/elixir
CMD iex -S mix help

It works as expected:

$ docker build -t elixir-test -f Dockerfile.system . && docker run --rm -it elixir-test
Erlang/OTP 24 [erts-12.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit]
...
Interactive Elixir (1.13.0) - press Ctrl+C to exit (type h() ENTER for help)

Now, let’s add Dockerfile for asdf:

# Dockerfile.asdf

FROM ubuntu

ARG DEBIAN_FRONTEND=noninteractive

RUN apt update -y
RUN apt upgrade -y
RUN apt install -y wget

# System installation of Erlang and Elixir according to https://elixir-lang.org/install.html
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && apt install -y --fix-broken ./erlang-solutions_2.0_all.deb
RUN apt update -y
RUN apt install -y esl-erlang
RUN apt install -y elixir

# asdf installation of Erlang and Elixir
RUN apt install -y curl git build-essential libssl-dev automake autoconf libncurses5-dev
RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.9.0
RUN echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
RUN bash -ic "asdf plugin add erlang && \
      asdf install erlang latest && \
      asdf plugin add elixir && \
      asdf install elixir latest"

WORKDIR /home/elixir
CMD bash -ic "asdf local erlang latest && asdf local elixir latest && iex -S mix help"
#CMD bash -ic "asdf local erlang system && asdf local elixir system && iex -S mix help"

This also works as expected:

$ docker build -t elixir-test -f Dockerfile.asdf . && docker run --rm -it elixir-test
Erlang/OTP 24 [erts-12.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit]
...
Interactive Elixir (1.13.3) - press Ctrl+C to exit (type h() ENTER for help)

However, when you uncomment last CMD line in Dockerfile.asdf so that system versions of Elixir and Erlang would be used then problems happen:

$ docker build -t elixir-test -f Dockerfile.asdf . && docker run --rm -it elixir-test
** (SyntaxError) /root/.asdf/shims/mix:3:12: syntax error before: '.'
    |
  3 | exec /root/.asdf/bin/asdf exec "mix" "$@"
    |            ^
    (elixir 1.13.0) lib/code.ex:1183: Code.require_file/2

Hope this helps.

Somehow, between outcommenting the the line . $HOME/.asdf/asdf.sh, checking different shell scripts and undoing the uncomment, something changed for the better and now everything works without problems. So for me it was some path problem.

For me using asdf exec as a command prefix still results in the same error as without.

I’m having a similar problem on Mac OS, where system versions of erlang, elixir and hex were installed before I added asdf.

When I’m inside a Phoenix project and run iex -S mix phx.new I get the same error as @jarmo. However, using the slightly more convoluted asdf exec iex -S mix phx.server works fine. Smells like some kind of path issue, but right now I’m not smart enough to see how it can be solved to work as usual.

Edit:

It seems to be related to the line . $HOME/.asdf/asdf.sh in my shell-config (~/.zshrc) that I added during asdf installation, or rather, the referenced file asdf.sh . Outcommenting that line gives me access to the system version of elixir (1.13.1) and I can still use asdf exec iex -S mix phx.server to get the asdf version.

$ type -a iex
iex is /home/jarmo/.asdf/shims/iex
iex is /usr/bin/iex
$ type -a mix
mix is /home/jarmo/.asdf/shims/mix
mix is /usr/bin/mix

About other version managers - I have only chruby installed for managing Rubies, but not anything else for Elixir/Erlang.

Yes, Erlang 23.0 and Elixir 1.11.2 were installed before and I used iex -S mix phx.server pretty often for development. Until yesterday asdf was not installed on my machine, but I needed newest versions of Erlang and Elixir to try out the newest version of Phonenix Framework, which made me to look into asdf, since I didn’t want to cause any issues to my older project by upgrading Erlang and Elixir system-wide.

When I comment out asdf in my .zshrc then I can use iex -S mix phx.server for my older project without any issues as was the case before installing asdf.

Also, as mentioned when I install the same versions of Erlang and Elixir with asdf and set them as local versions for the same older project then everything works too so it’s not that big of a problem that system installations will not work - I can even uninstall them since everything works with asdf too.