Edit: Please note there is a newer version of this guide here: https://astonj.com/how-to-set-up-a-ruby-and-elixir-dev-environment-on-macos-2021/
Having recently started afresh on macOS, I thought I’d make some notes on setting up a new dev environment. In this post we’ll set up a fresh dev environment for Ruby and Elixir – but you can use this guide for any similar web development set-up since the version manager we’ll be using (asdf) can be used for lots and lots and lots of different languages.
If you don’t need Ruby or 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 this in terminal:
Homebrew
In the terminal copy and paste the following:
In your .zshrc
file add:
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
fi
Let’s get brewing – and install Postgres, ImageMagick and git
Let’s update Homebrew first:
Postgres
Then:
Then to start Postgres and on startup, run:
Then create your initial db:
Then:
CREATE ROLE postgres LOGIN CREATEDB;
That will create your Postgres user (use CTRL Z to exit).
Git and ImageMagick
brew install git
Then in terminal:
git config --global user.email "youremail@yourdomain.com"
Installing asdf
In terminal, type:
Then in terminal run:
This will add the following to the bottom of your ~/.zshrc
file:
Installing asdf plugin dependencies
In terminal:
coreutils automake autoconf openssl \
libyaml readline libxslt libtool unixodbc \
unzip curl
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:
To see which versions are available:
Then install the versions you want with the following, just replace 2.6.5
with the version you need:
Then set your preferred defaults with:
And to use a specific version in any particular directory:
To add new Rubies:
Or simply:
Rubygems and Rails
Open a fresh terminal window and:
For Rails:
brew install yarn
Restart terminal and check your versions by:
rails -v
Installing Elixir & Erlang
Skip if you don’t need Elixir and Phoenix
In terminal:
asdf plugin-add Elixir
To see which versions are available:
asdf list-all erlang
Then install the versions you want with the following, just replace version numbers with whichever versions you need:
asdf global erlang 22.2.3
asdf install elixir 1.9.4-otp-22
asdf global elixir 1.9.4-otp-22
And to use a specific version in any particular directory:
Installing Hex and Phoenix
Phoenix uses Brunch.io which relies on npm, the Node.js package manager, so lets install that as well via asdf:
brew install gpg
bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring
asdf install nodejs 13.7.0
asdf global nodejs 13.7.0
To install Phoenix:
Finally, check your versions by:
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:
cd ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
git clone git://github.com/elixir-lang/elixir-tmbundle Elixir.tmbundle
MacVim
Next you’ll want to use Janus, which can be installed by running this in terminal:
In it paste:
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:
To install the Elixify theme download from here and follow the instructions for MacVim.
cd ~/.vim/colors
mvim Elixify.vim
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 am really loving btw!!