Installing Your Development Environment

Like many great programming projects, Phoenix builds on some of the best open source projects available. You’ll install all of those dependencies now, using the best resources you can find for your own environment.

Elixir Needs Erlang

Erlang provides the base programming virtual machine. It supports our base programming model for concurrency, failover, and distribution. It also provides an exhaustive programming library that’s the foundation of the Elixir language. Go download Erlang,[6] choosing the best installation for your environment. You’ll want version 20.0 or greater.

Phoenix Needs Elixir

The Elixir programming language powers Phoenix. You can find installation instructions on the Elixir[7] site. You’ll want version 1.6 or greater. Before you work through this book, it would be helpful to know Elixir. Good online resources[8] exist, but we recommend the excellent book Programming Elixir [Tho16], by Dave Thomas, which will get you all of the way through concurrency concepts and OTP. For now, think of OTP as the layer for managing concurrent, distributed services. Rest assured that you’ll get more details on OTP later.

You can check to see that Elixir and Erlang are working correctly, like this:

 $ ​​elixir​​ ​​-v
 Elixir 1.8.0

Let’s also install Hex, Elixir’s package manager:

 $ ​​mix​​ ​​local.hex
 * creating ~/.mix/archives/hex-0.19.0

Elixir is working, and if you were building strictly a JSON API or a very simple application it would be enough. For this application, since you’ll be building both frontend and backend with Phoenix, you need to install a database and the code that will help you manage assets. That means you’ll have to install PostgreSQL and Node.js.

Ecto Needs PostgreSQL

Ecto uses the PostgreSQL[9] database adapter by default, and Phoenix adopts this default. It’s the database engine we’ll be using throughout the book, so you’ll need version 9.5 or greater. You can check your local version like this:

 $ ​​psql​​ ​​--version
 psql (PostgreSQL) 9.5.1

Node.js for Assets

Web development often requires web assets to be processed for deployment. Rather than reinvent the wheel, developers can optionally use Node.js tools for those services. Phoenix will use webpack.js.org to compile static assets such as JavaScript and CSS by default, and webpack uses npm, the Node.js package manager, to install its dependencies. Once it’s installed, Phoenix will rely on them for asset management. Follow the directions on the Node.js[10] site and make sure you have version 5.3.0 or greater. Test your installation like this:

 $ ​​node​​ ​​--version
 v5.3.0

Phoenix has a feature called live reloading, which automatically reloads web pages as our assets and templates change. If you’re running Linux, you’re also going to need to install inotify[11] to support live reloading. Other operating systems are covered.

We’re finally ready for Phoenix.

Phoenix

You’re going to work in the Elixir language to write your code, so you’ll use the Mix utility to run development tasks. Let’s use Mix to install the Phoenix archive, and then to install Phoenix itself:

 $ mix archive.install hex phx_new
 
 * creating ~/.mix/archives/phx_new

In case you already had Phoenix installed, make sure you have version v1.4.7 or later:

 $ mix phx.new -v
 Phoenix v1.4.7

Now you’re ready to roll!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.178.237