Using Elixir Livebook for Phoenix Development

July 4, 2021


This article describes my Elixir development workflow using Livebook.


In this post, I would like to quickly explain how you can use Elixir Livebook to get quick feedback when developing application using Elixir, Phoenix, and potentially even pure Erlang applications.

Install latest Erlang and Elixir

First, let’s install Livebook. You will need Elixir 1.12 or later. If you are working with the asdf version manager (which you should, anyway), you can install the latest versions of Erlang and Elixir using the following commands:

# Optional, will build Erlang with inline documentation
export KERL_BUILD_DOCS="yes"

asdf install elixir latest
asdf install erlang latest

Please be aware that you need to install asdf plugins for Erlang and Elixir and their respective dependencies. This will vary based on your operating system.

After the installation, take note of the precise versions installed and set the newly installed versions as your global tool versions:

asdf global erlang 24.0.3
asdf global elixir 1.12.2-otp-24

Install Livebook as escript

Install rebar3, hex, and Livebook:

mix local.hex --force
mix local.rebar --force
mix escript.install hex livebook

If you are using asdf, you will need to tell asdf to generate a shim for the livebook command. This way you can call the command livebook anywhere in your console:

asdf reshim

Up and running

If everything in the previous section has worked correctly, you should now be able to run Livebook locally, like so:

$ livebook server
00:30:56.878 [info]     :alarm_handler: {:set, {:system_memory_high_watermark, []}}
[Livebook] Application running at http://localhost:8080/?token=mqrhw2emihrmb6utaovqzmq743umdq73

When you click on the link in the terminal, you should see Livebook’s welcome screen, like the one in the screenshot below:

JSON API running from an Elixir release

Now, click on the bright purple New notebook button in the upper right corner of the page. You can now pick a title for your new notebook. You can add Elixir and Markdown sections or add inputs for data input. The specifics of Livebook usage have been covered in José Valim’s excellent screencasts covering version 0.2 and the initial announcement of Livebook, so I will not cover them here.

Connecting your application to Livebook

You can connect to any Elixir application, including one that is already running (even your production server), as long as you know the node name and its cookie. cd into your Phoenix application and run:

iex --sname livebook --cookie livebook -S mix

This command

<< Back to blog