Installation
In order to build a Phoenix application, we will need a few dependencies installed in our Operating System:
- the Erlang VM and the Elixir programming language
- a database - Phoenix recommends PostgreSQL but you can pick others or not use a database at all
- and other optional packages.
Please take a look at this list and make sure to install anything necessary for your system. Having dependencies installed in advance can prevent frustrating problems later on.
Elixir 1.12 or later
Phoenix is written in Elixir, and our application code will also be written in Elixir. We won't get far in a Phoenix app without it! The Elixir site maintains a great Installation Page to help.
If we have just installed Elixir for the first time, we will need to install the Hex package manager as well. Hex is necessary to get a Phoenix app running (by installing dependencies) and to install any extra dependencies we might need along the way.
Here's the command to install Hex (If you have Hex already installed, it will upgrade Hex to the latest version):
$ mix local.hex
Erlang 22 or later
Elixir code compiles to Erlang byte code to run on the Erlang virtual machine. Without Erlang, Elixir code has no virtual machine to run on, so we need to install Erlang as well.
When we install Elixir using instructions from the Elixir Installation Page, we will usually get Erlang too. If Erlang was not installed along with Elixir, please see the Erlang Instructions section of the Elixir Installation Page for instructions.
Phoenix
To check that we are on Elixir 1.12 and Erlang 22 or later, run:
elixir -v
Erlang/OTP 22 [erts-10.7] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Elixir 1.12.1
Once we have Elixir and Erlang, we are ready to install the Phoenix application generator:
$ mix archive.install hex phx_new
The phx.new
generator is now available to generate new applications in the next guide, called Up and Running. The flags mentioned below are command line options to the generator; see all available options by calling mix help phx.new
.
PostgreSQL
PostgreSQL is a relational database server. Phoenix configures applications to use it by default, but we can switch to MySQL, MSSQL, or SQLite3 by passing the --database
flag when creating a new application.
In order to talk to databases, Phoenix applications use another Elixir package, called Ecto. If you don't plan to use databases in your application, you can pass the --no-ecto
flag.
However, if you are just getting started with Phoenix, we recommend you to install PostgreSQL and make sure it is running. The PostgreSQL wiki has installation guides for a number of different systems.
inotify-tools (for Linux users)
Phoenix provides a very handy feature called Live Reloading. As you change your views or your assets, it automatically reloads the page in the browser. In order for this functionality to work, you need a filesystem watcher.
macOS and Windows users already have a filesystem watcher but Linux users must install inotify-tools. Please consult the inotify-tools wiki for distribution-specific installation instructions.
Summary
At the end of this section, you must have installed Elixir, Hex, Phoenix, and PostgreSQL. Now that we have everything installed, let's create our first Phoenix application and get up and running.