Random Musings

O for a muse of fire, that would ascend the brightest heaven of invention!


From Zero to Phoenix on Ubuntu

Monday, 16 Oct 2023 Tags: elixirphoenixubuntu

Here are some brief notes on getting an up-to-date Phoenix setup on a fresh Ubuntu VM, suitable for newcomers to Linux, Elixir, and Phoenix. Includes PostGres.

  • assuming you have Ubuntu v22.0.4.3 LTS, amd64
  • access via a local terminal or via ssh, either is fine
  • where prompted, just choose the default answer most times

Tools

$ sudo -s
# apt update
# apt upgrade
# apt install mosh git tmux fd-find rsync htop ripgrep \
  fish neovim net-tools inotify-tools
# echo "tmpfs /tmp tmpfs rw,nosuid,nodev" | tee -a /etc/fstab

Erlang and Elixir

# add-apt-repository ppa:rabbitmq/rabbitmq-erlang
# apt update
# apt install elixir erlang-dev erlang-xmerl erlang-eunit
# reboot

the final reboot is only necessary if your apt upgrade requires it

Database

# apt install postgresql
# sudo -u postgres psql
postgres=# ALTER USER postgres with encrypted password 'postgres';

Check the bits

  • we should have a database, elixir & erlang
$ netstat -l |grep postgres
tcp        0      0 localhost:postgresql    0.0.0.0:*               LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     28918    /var/run/postgresql/.s.PGSQL.5432
$ mix hex.info
Hex:    2.0.6
Elixir: 1.15.7
OTP:    26.1.2

Built with: Elixir 1.14.2 and OTP 23.3

Make a new Phoenix App

  • make a dir to hold our source code
  • install the Phoenix generator
  • generate a working application scaffold
$ mkdir ~/src && cd ~/src
$ mix archive.install hex phx_new
$ mix phx.new --binary-id demo

$ cd demo
$ git init . && git add . && git commit -am ':mix phx.new demo'

$ mix ecto.reset
$ iex -S mix phx.server