Mac laptop

chuttersnap

Simple Ruby/Rails Setup on macOS

I try and keep my development environment as ‘light’ as possible, so with that in mind here’s my serious (in that I make a living from coding) but simple Ruby and Rails setup for a Mac.

The reason for writing this? Managed to nuke my machine’s install and thus had an opportunity to review my toolkit.

Homebrew

Homebrew is better than Macports in nearly every way. Open source recipes to manage stuff you used to have install yourself.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You’ll want to install some dependancies. You’ll also need gcc on modern macOS to install rubies younger than 2.0.

brew install gdbm libffi libyaml openssl readline
brew install gcc48

This then makes installing the rest, super easy.

chruby

chruby on github

I’m a bit fan of the simplest thing that can possibly work. This library is the latest in a line from rvm through rbenv to easily manage multiple ruby versions on your development machine.

brew install chruby

So good it caused the authors of other ‘simple ruby managers’ to retire their projects.

ruby-install

ruby-install is used for installing your Rubies. Good name, no?

brew install ruby-install

Install some Rubies

ruby-install ruby 2.3
ruby-install ruby 2.4

shellAdd the following lines to your ~/.bash_profile as described in the chruby readme.

source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
chruby ruby-2.4

First line enables chruby, second line auto-switches rubies for each project you have based on a .ruby-version (a cross ruby installer convention) and the third line selects your default ruby.

Local Database

I’m all about the Heroku deployment, so I use PostgreSQL locally as well. It’s good practice to use the same DB type and version in development as you do in production.

brew install postgres
brew services start postgresql

Rails itself

You’ll want bundler and rails as a bare minimum.

gem install bundler
gem install rails

Let’s Roll

Now to get going you can:

rails new yourapplicationname -d postgres
cd yourapplicationname

It is good practice to include a .ruby-version file in the root of your app. It’ll look like this if you’re on the latest version of ruby.

2.4.2

But otherwise, job done.

bundle
bundle exec rails server

And navigate to localhost:3000.


There’s a script for that?

I do have a few scripts that I try and keep maintained that let me quickly setup a development machine.

andycroll/macsetup on github if you’re interested.

Last updated on May 5th, 2016