Today I want to share a rather pleasant experience I’ve been having in the world of web development, and that is working with Elixir.
Phoenix is a web framework built on top of Elixir, think Rails for Elixir. And it’s been widely adopted by many Ruby developers as a way to overcome performance limitations with a familiar syntax and similar patterns.
Let’s get to it. This guide assumes that you’re using MacOS, although the same could be performed on an Unix or Windows-based machine.
First we need to get Elixir installed:
brew update && brew install elixir
Because Elixir is still on version 1.4 (as the time of this writing), there haven’t been many attempts at version managers yet, however if you need to manage multiple versions of Elixir, asdf is a good candidate and I recommend you to check it out.
If everything worked out, you should be able to verify if Elixir has been installed on your system by running:
Elixir comes with an interactive mode included (think
iex(1)> 40 + 2 42 iex(2)> "hello" <> " world" "hello world"
When you install Elixir for the first time, you will need to get
Hex installed. Hex is a package manager for Elixir and Erlang libraries (Again, think RubyGems, npm etc…)
Here’s the command to install Hex (If you already have it installed, it’ll just upgrade to the latest version):
Now onto the interesting bits. Installing Phoenix is as easy as:
mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez
Basically what this will do is, it will query Hex for the latest published version of Phoenix and make it available for use with Elixir.
Once you have Phoenix installed, there’s a couple of dependencies to it. And they’re pretty reasonable IMO:
To install both, simply run:
brew install node &&
brew install postgres
PS.: I have had issues with my postgresql install via Homebrew, because I forgot my username/password. Make sure you have those before you continue.
Creating your first Phoenix Project
mix phoenix.new my_app and cd into
my_app to browse the files.
You can access the console by running:
iex -S mix phoenix.server
Before starting up the server, you will need to create the DB:
And then run the server:
Phoenix has a few preset tasks to help you get started and learn more about the framework:
mix phoenix.gen.channel # Generates a Phoenix channel mix phoenix.gen.html # Generates controller, model and views for an HTML based resource mix phoenix.gen.json # Generates a controller and model for a JSON based resource
The above commands are somewhat equivalent to Rails’
Hope this guide is helpful and if you have any questions, please let me know.