Erlang and Elixir with asdf in Raspberry 4 with Ubuntu 20.04

To install the latest/current versions of erlang (23.0.2) and elixir (1.10.3), follow the instructions below:

Install asdf ( full instructions https://asdf-vm.com/#/core-manage-asdf-vm):

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.8

Add the following two lines in your ~/.bashrc file:

# Add asdf version manager 
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

Reload/Source your bash file with

source ~/.bashrc

Install the erlang plugin

asdf plugin add erlang

If you get the following warnings:

...
Extracting source code
Building Erlang/OTP 23.0.2 (asdf_23.0.2), please wait...
WARNING: It appears that a required development package 'libssl-dev' is not installed.
WARNING: It appears that a required development package 'automake' is not installed.
WARNING: It appears that a required development package 'autoconf' is not installed.
WARNING: It appears that a required development package 'libncurses5-dev' is not installed.
Configure failed.
...

Install the missing packages:

sudo apt install libssl-dev automake autoconf libncurses5-dev

Install latest erlang version:

asdf install erlang latest
...
Erlang/OTP 23.0.2 (asdf_23.0.2) has been successfully built
...

Set it up globally (if you want):

asdf global erlang 23.0.2

Add elixir plugin:

asdf plugin add elixir

Install latest elixir version (1.10.3):

asdf install elixir latest

Set it up globally:

asdf global elixir 1.10.3-otp-23

Finally you can also install the latest Phoenix version (1.5.3):

mix archive.install hex phx_new 1.5.3

Using a primary key not named id with Ecto and Mysql

Problem

You would like to use a legacy or a database you don’t have control over, with Phoenix, but the primary key of the table it is not named ‘id’.

** (Mariaex.Error) (1054): Unknown column 'p0.id' in 'field list'

Solution

You can define the primary key using the @primary_key as in:

 @primary_key {:id_other_name, :integer, []}
  schema "db_table" do
    field :description, :string
    ...
  end

Taken from here

Starting Phoenix server in a different port than 4000

Problem

You would like start a phoenix application in a port different from the default 4000, by using something similar to the rails:

rails s -p 4001

Solutin

You will need to change the config/dev.exs file to include the following:

http: [port: System.get_env("PORT") || 4000],

and then start the server with:

PORT=4002 mix phoenix.server

Taken from the answer here

Request failed (404) ** (Mix) Package fetch failed and no cached copy available

Problem

You are trying to use hex for installing dependencies but when you are behind a proxy you get the following message:

Request failed (404)
** (Mix) Package fetch failed and no cached copy available

Solution

You can use the following to set up hex (taken from the answer here:

mix hex.config http_proxy http://proxy.mycompany.com

Error: Brunch 2+ requires node v4.0+. Upgrade node or use older brunch for old node.js: npm i -g brunch@1

Problem

Trying to start a new phoenix application while your node installation is old you get the following error:

Error: Brunch 2+ requires node v4.0+. Upgrade node or use older brunch for old node.js: npm i -g brunch@1 -g brunch@1

Solution

You will need to upgrade your node installation by following the steps below:

$> node -v
v0.10.32
$> sudo yum install nodejs npm (if npm is not available)
$> npm cache clean -f
$> npm install -g n
$> sudo /path/n/was/installed(ie /home/kosmas/bin/n) stable
$> node -v
v5.10.1

Updating Phoenix from 0.3.1 to 0.4.0

Problem

You would like to upgrade to the latest version of Phoenix 0.4.0 from the previous version of 0.3.1. When you try to update the dependencies and try to start phoenix again (mix phoenix.start) you get the following error:

** (Mix) You're trying to run :your_app_name on Elixir v1.0.0-rc1 
but it has declared in its mix.exs file it supports 
only Elixir ~> 0.15.0

Solution

After upgrading your Elixir version to the latest (1.0.0-rc1), and updating the path to your elixir installation so that it uses the new one, clear the dependencies from your project:

mix deps.clear --all

Change the dependency in your mix.exs file to be as the following:

def project do
    [ app: :your_app_name,
      version: "0.0.1",
      elixir: "~> 1.0.0-rc1",
      elixirc_paths: ["lib", "web"],
      deps: deps ]
  end

and then get the dependencies again with:

mix deps.get

after that you should be able to start your phoenix project with tne new version.