Skip to content

Latest commit

 

History

History
108 lines (76 loc) · 3.05 KB

elixir.md

File metadata and controls

108 lines (76 loc) · 3.05 KB

Setup for Elixir projects

It's mostly the same as setting up environments for Ruby or JavaScript, with some nuances:

  • Postgres: to make your life easier, create a user with name postgres password postgres. This is the default for most Phoenix projects.
  • Asdf: this is the preferred version manager for Elixir, Erlang and Node.js.

All of these steps are optional, but recommended.


Postgres

Phoenix projects default to connecting to Postgres with the username postgres and password postgres. This isn't so easy to override, so let's just keep that as the default.

  • Install postgres. In OSX, use Homebrew to install it.

    # OSX only
    brew install postgres
  • Use homebrew/services to start Postgres. Optional but recommended.

    # OSX only
    brew tap homebrew/services
    brew services start postgres
  • Create a postgres user. Use PostgreSQL's createuser to create a new user. Give it a password postgres.

    $ createuser --superuser postgres -P
      Enter password for new role:
      Enter it again:

asdf

Asdf is a version manager for everything: Ruby, Elixir, Erlang, Node.js, and so on.

  • Install asdf via git.

    git clone https://github.com/asdf-vm/asdf.git ~/.asdf
  • Add it to bashrc. (If you're on zsh, add it to ~/.zshrc. For fish shell and others, see asdf setup docs).

    # bash / Ubuntu
    echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
    echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
    # bash / OSX
    echo '. $HOME/.asdf/asdf.sh' >> ~/.bash_profile
    echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bash_profile
    # Zsh
    echo '. $HOME/.asdf/asdf.sh' >> ~/.zshrc
    echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc
  • Add plugins for Erlang, Elixir and Node.js.

    asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git
    asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
    asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git

Install Erlang/Elixir/Node.js

  • If you have a project with a .tool-versions, simply run asdf install.

    cd my-project
    asdf install
  • To configure "global" versions in asdf, create ~/.tool-versions. Here's a fair starting point.

    # These are stable versions as of April 2017.
    # To check newer versions, use: `asdf list-all nodejs`
    cd ~
    echo 'erlang 19.2'   >> .tool-versions
    echo 'nodejs 6.10.2' >> .tool-versions
    echo 'elixir 1.4.2'  >> .tool-versions
    asdf install

Alternatives

  • Postgres.app is another way to install Postgres.
  • Kiex is an Elixir version manager. It doesn't manage Erlang installations (a dependency of Elixir), however.
  • You may also install Erlang and Elixir via Homebrew, though it may be difficult to switch versions later on.