From Zero to Phoenix on Ubuntu
Monday, 16 Oct 2023
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
- switch to root user
- update base system
- install my favourite tools, and some needed for phoenix
- add a memory-backed tmpfs
- https://ubuntu.com/blog/data-driven-analysis-tmp-on-tmpfs
$ 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
- we use a 3rd party repository to get a nice fresh erlang & elixir as ubuntu is a bit behind
- https://elixir-lang.org/install.html#gnulinux
# 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
- don’t strictly need this but it’s the default DB for Phoenix
- set a terrifically bad but convenient password
- mostly cribbed from https://ubuntu.com/server/docs/databases-postgresql
# 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