Elixir installation/upgrade and deployment on Centos 7

Hi all,

I’m hoping you guys can help me out, I’ve got myself in a bit of a pickle on my server - it’s not something I need to visit very often.

A couple of years ago I set up my Centos 7 server with Elixir and Erlang. I can’t remember how I installed Elixir, (I failed to record the process I followed and won’t make that mistake again).

So for the last two years I’ve had:

Elixir v1.7.0-dev (don’t know why I ended up with the dev build)
Erlang/OTP 20

And everything has been fine.

Yesterday I started a new project and had some problems building the release with edeliver. The error I received pointed me to: https://github.com/boldpoker/edeliver/issues/94 so I decided to try and upgrade my Elixir version assuming (rightly or wrongly) that it would fix the issue that is described relating to mix.

I initially assumed I would have used yum so I did yum upgrade elixir which resulted in Erlang upgrading to 22 but Elixir remaining the same at 1.7.0-dev. This seems to have just caused more problems, presumably because my Elixir version was compiled with Erlang 20.

So what I would like to do is to completely remove Elixir and install the latest stable version that is compatible with Erlang/OTP 22 on Centos 7.

yum erase elixir results in No Match for argument: elixir, so I mustn’t have used yum to install Elixir.

which elixir points to /usr/local/bin/elixir which appears to be a symlink to /opt/elixir/bin/elixir which I guess is the compiled binary, so I assume I could just delete that (with the corresponding mix build etc in the same dir). But I don’t want to start thrashing around with things without confirmation/advice - I’ve done enough damage already.

So can anyone suggest my next course of action for:

  1. Completely removing Elixir, and

  2. The recommended installation process and latest stable version that works with Erlang/OTP 22 on Centos 7.

Many Thanks

You installed from source, a version of elixir that was newer than 1.6, but not reached 1.7 yet…

So you probably really updated the elixir package from the system to a version that is more recent then the system version you had before, but your “local” elixir version is at an earlier position in PATH.

Try which -a elixir to see how many elixir versions are visible from the PATH.

which elixir | while read line; do printf "%s:\n%s" "$line" "$($line --version)"; done should tell you the version of each (untested)

Depends on how exactly you installed it. So as you can’t remember that, its hard… Though perhaps search your users and roots homes for the elixir source repository, if you find it, open the Makefile and manually undo the steps done by the install task.

2 Likes

I can try to point you in the correct direction here, but I am not able to give you the exact set of instructions.

So you can grab the bash script I used in this Stackoverflow answer and adapt it from Ubuntu to Centos. I think it should not be too hard.

For your convenience the bash script for Ubuntu:

#!/bin/sh

set -eu

Main() {

    local ERLANG_VERSION=${1? Missing Erlang version. Check the latest version at https://www.erlang-solutions.com/resources/download.html}
    local ERLANG_DOWNLOAD_URL=https://packages.erlang-solutions.com/erlang/debian/pool/esl-erlang_${ERLANG_VERSION}-1~ubuntu~bionic_amd64.deb

    local ELIXIR_VERSION=${2? Missing Erlang version. Check the latest version at https://www.erlang-solutions.com/resources/download.html}
    local ELIXIR_DOWNLOAD_URL=https://packages.erlang-solutions.com/erlang/debian/pool/elixir_${ELIXIR_VERSION}-1~ubuntu~bionic_all.deb

    local PHOENIX_VERSION="${3? Missing Phoenix version to install!!!}"

    local NODEJS_VERSION="${4? Missing NodeJS version to install!!!}"

    apt update
    apt -y upgrade
    apt -y -q install --no-install-recommends \
        ca-certificates \
        curl \
        build-essential \
        procps \
        libncurses5 \
        libwxbase3.0-0v5 \
        libwxgtk3.0-0v5 \
        libsctp1

    apt -y -f install

    printf "\nERLANG DOWNLOAD URL: ${ERLANG_DOWNLOAD_URL}\n"
    curl -fsSL -o esl.deb "${ERLANG_DOWNLOAD_URL}"
    dpkg -i esl.deb
    rm -f esl.deb

    printf "\nELIXIR DOWNLOAD URL: ${ELIXIR_DOWNLOAD_URL}\n"
    curl -fsSL -o elixir.deb "${ELIXIR_DOWNLOAD_URL}"
    dpkg -i elixir.deb
    rm -f elixir.deb

    printf "\nPHOENIX VERSION: ${PHOENIX_VERSION}\n"

    # installs the package manager
    mix local.hex --force

    # installs rebar and rebar3
    mix local.rebar --force

    mkdir -p "${HOME}/bin"
    ln -s "${HOME}"/.mix/rebar "${HOME}"/bin/rebar
    ln -s "${HOME}"/.mix/rebar3 "${HOME}"/bin/rebar3

    mix archive.install --force hex phx_new ${PHOENIX_VERSION}

    # INSTALL NODEJS
    printf "\nNODEJS VERSION: ${NODEJS_VERSION}\n"
    curl -sL https://deb.nodesource.com/setup_"${NODEJS_VERSION}".x | sh -
    apt install -y -q --no-install-recommends nodejs
}

Main ${@}

So after you convert it to Centos 7, you can install an Elixir Phoenix stack with bash install-stack.sh <erlang-version> <elixir-version> <phoenix-version> <nodejs-version>:

bash install-stack.sh 22.3.3 1.10.3 1.5.1 10

Now test it works:

mix phx.new hello --no-ecto && cd hello && mix test
2 Likes

Easy ways

  • Try to use packaged Erlang OTP - e.g. Check out Erlang Solutions downloads - it provides Erlang OTP 22 for CentOS 7.
  • If you want to buildErlang OTP - use asdf-erlang, or kerl (which asdf-erlang uses)
  • Use pre-compiled Elixir from Bob

If you really want to build by youself… I have Dockerfile for Redhat Universal Base Image 7 (ubi7) to build Erlang from source, and use pre-compiled Elixir (from Bob)

Building erlang

src

Note - I had to install centos packages since ubi7 does not have all tools/libraries.

Also check out CentOS section from asdf-erlang

RUN set -xe \
    && yum -y update \
    && buildDepsUBI="autoconf automake gcc make openssl-devel" \
    && buildDepsCentOS="ncurses-devel" \
    && yum install -y $buildDepsUBI \
    && yum-config-manager --add-repo=http://mirror.centos.org/centos/7/os/x86_64/ \
    && rpm --import http://mirror.centos.org/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 \
    && yum install -y $buildDepsCentOS \
    && yum clean all \
    && yum-config-manager --disable mirror.centos.org_centos_7_os_x86_64_ \
    && curl -fSL -o otp-src.tar.gz "$OTP_DOWNLOAD_URL" \
    && echo "$OTP_DOWNLOAD_SHA256  otp-src.tar.gz" | sha256sum -c - \
    && export ERL_TOP="/usr/src/otp_src_${OTP_VERSION%%@*}" \
    && mkdir -vp $ERL_TOP \
    && tar -xzf otp-src.tar.gz -C $ERL_TOP --strip-components=1 \
    && rm otp-src.tar.gz \
    && ( cd $ERL_TOP \
      && ./otp_build autoconf --build="x86_64" \
      && ./configure \
      && make -j$(nproc) \
      && make install ) \
    && find /usr/local -name examples | xargs rm -rf \
    && rm -rf "$ERL_TOP" \
    && yum autoremove -y $buildDepsUBI $buildDepsCentOS \
    && yum clean all

Using pre-compiled Elixir

src

RUN set -xe \
    && yum install -y ca-certificates curl unzip \
    && curl -fSL -o elixir-precompiled.zip $ELIXIR_DOWNLOAD_URL \
    && echo "${ELIXIR_DOWNLOAD_SHA256}  elixir-precompiled.zip" | sha256sum -c - \
    && unzip -d /usr/local elixir-precompiled.zip \
    && rm elixir-precompiled.zip \
    && yum remove -y unzip \
    && yum clean all \
    && mix local.hex --force
3 Likes

Thanks to everyone for your help. That gives me a few things I can look into and try.

I’ll look into it tomorrow, and if/when I sort it I’ll post back here in case anyone has a similar problem.

:+1:

1 Like

I have been unable to resolve this, so have set up a new Ubuntu server.

Many thanks to everyone who to tried to help.

I now have one final problem to resolve with the Ubuntu server, I have posted the question here: Unable to access Phoenix app after deployment to Ubuntu 18.04

I appears to be Ubuntu/Nginx related if anyone can help.