How to set-up a Ruby and Elixir dev environment on macOS (2021)

This is the latest version of my dev env set-up guide, perfect for use after getting a new machine or carrying out a fresh install of macOS. You can use this guide for similar web development set-ups too, since the version manager we’ll be using (asdf) is perfect for a large number of different languages.

If you don’t need Ruby or don’t need Elixir, you can just omit those steps. We’ll also add a few other common web development tools or packages. In short, we’ll be covering installation of:

  • Xcode
  • Command line tools
  • Homebrew
  • ImageMagic
  • Git
  • Postgres
  • TextMate
  • MacVim
  • Asdf
  • Ruby
  • Rubygems
  • Rails
  • Erlang
  • Elixir
  • Hex
  • Phoenix

Xcode

Simply download and install Xcode from the App store.

Command Line Tools

Once Xcode has installed, open it, then go to preferences > downloads, and install command line tools. Or alternatively, enter the following in terminal – be sure to start Xcode afterwards so you can agree to their terms:

xcode-select --install

Homebrew

In the terminal copy and paste the following:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Let’s get brewing – and install Postgres, ImageMagick and git

Let’s update Homebrew first:

brew update

Postgres

Then:

brew install postgres

Then to start Postgres and on startup, run:

brew services start postgresql

Then create your initial db:

createdb

Then:

psql
CREATE ROLE postgres LOGIN CREATEDB;

That will create your Postgres user (use CTRL Z to exit).

Git and ImageMagick

brew install imagemagick
brew install git

Then in terminal:

git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"

Installing asdf

In terminal, type:

brew install coreutils curl
brew install asdf

Then in terminal run:

echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ~/.zshrc

This will add the following to the bottom of your ~/.zshrc file:

. /usr/local/opt/asdf/asdf.sh

In terminal:

If you need to upgrade asdf, use brew upgrade asdf.

How to remove asdf

If you ever need to remove asdf, you can do so pretty easily:

  • In your .zshrc remove the line that was added on installation:. /usr/local/opt/asdf/asdf.sh
  • Run rm -rf ~/.asdf/ ~/.tool-versions to completely remove all the asdf files from your system.
  • In terminal: brew uninstall --force asdf

Installing Ruby

Skip if you don’t need Ruby and Rails…

In terminal:

asdf plugin-add ruby

To see which versions are available:

asdf list-all ruby

Then install the versions you want with the following, just replace 2.7.2 and 3.0.0 with which versions you need:

asdf install ruby 2.7.2
asdf install ruby 3.0.0

Then set your preferred defaults with:

asdf global ruby 3.0.0

And to use a specific version in any particular directory:

asdf local ruby 2.7.2

To add new Rubies:

asdf plugin-update ruby
asdf list-all ruby

Or simply:

asdf install ruby latest

Rubygems and Rails

Open a fresh terminal window and:

gem update --system

If you would prefer docs weren’t installed, add this to your ‘.gemrc’ file (create one if it doesn’t exist):

gem: --no-document

For Rails:

gem install rails
brew install yarn

Open a new terminal window and check your versions by:

ruby -v
rails -v

Installing Elixir & Erlang

Skip if you don’t need Elixir and Phoenix

In terminal:

asdf plugin-add Erlang
asdf plugin-add Elixir

To see which versions are available:

asdf list-all erlang
asdf list-all elixir

Then install the versions you want with the following, just replace version numbers with whichever versions you need:

asdf install erlang 23.2.3
asdf global erlang 23.2.3
asdf install elixir 1.11.3-otp-23
asdf global elixir 1.11.3-otp-23

And to use a specific version in any particular directory:

asdf local elixir 1.11.3-otp-23

Installing Hex and Phoenix

mix local.hex

Phoenix uses Brunch.io which relies on npm, the Node.js package manager, so lets install that as well via asdf:

asdf plugin-add nodejs
brew install gpg
bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring
asdf list-all nodejs
asdf install nodejs 15.8.0
asdf global nodejs 15.8.0

To install Phoenix:

mix archive.install hex phx_new 1.5.7

Finally, check your versions by:

elixir -v
mix phx.new --version

Doesn’t that feel good? Now you can install your favourite code editors!

Code Editors

I’m going to install two here, TextMate and MacVim 😀

TextMate 2

Download from here: https://macromates.com/download

Download my Elixify theme and follow the instructions from here (but you just need to double click on the TextMate 2 theme called Elixify.tmbundle)

Install Elixir Bundle:

mkdir -p ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
cd ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
git clone git://github.com/elixir-lang/elixir-tmbundle Elixir.tmbundle

MacVim

brew install MacVim

If you want to use Janus, it can be installed by running this in terminal:

curl -L https://bit.ly/janus-bootstrap | bash
vim ~/.gvimrc.after

In it paste:

color elixify
set guifont=Monaco:h12
let g:NERDTreeWinPos = "right"
set guioptions-=T " Removes top toolbar
set guioptions-=r " Removes right hand scroll bar
set go-=L " Removes left hand scroll bar
autocmd User Rails let b:surround_{char2nr('-')} = "<% \r %>" " displays <% %> correctly
:set cpoptions+=$ " puts a $ marker for the end of words/lines in cw/c$ commands

Then in terminal, to give it some breathing space at the top do:

defaults write org.vim.MacVim MMTextInsetTop ‘5’

To install the Elixify theme download from here and follow the instructions for MacVim.

mkdir ~/.vim/colors
cd ~/.vim/colors
open .
//copy Elixify.vim there

If you’re looking for even more code editors, VSCode is currently very popular but if you want to try something new, why not give Onivim a try? It wants to bring us the best of Vim and VSCode (there’s a monthly giveaway and discount on devtalk if you’re interested: onivim.devtalk.com).

That’s it – you now have a fully working dev environment for Ruby, Elixir, Erlang, Node and any other language you want to add via the numerous supported by asdf… which I highly recommend btw!!