Ruby dev environment (Yosemite)

Having recently reformatted my Mac, I thought I’d jot some notes down on setting up a Ruby dev environment too.

In this post we’ll set up our fresh dev enviroment for Ruby, and cover installing and setting up the following…

  • Xcode/GCC
  • Command line tools
  • Homebrew
  • Chruby
  • Ruby
  • Rubygems
  • Rails
  • Postgres
  • MacVim

Xcode or GCC

Simply download and install Xcode from the App store, OR, get GCC from here.

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:

xcode-select --install

Homebrew

In the terminal copy and paste the following:

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

Chruby, Rubygems, Rails, Git, ImageMagick

Chruby is the new Ruby version manager that most Ruby devs seem to be using and recommending nowadays. I recently tried it and like it too! (Note, not to be installed if you have or intend to use RVM or Rbenv.)

Chruby

brew update
brew install chruby
brew install ruby-install
ruby-install ruby 2.2.2

In ‘~/.bash_profile’ add the following lines:

# Chruby
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
chruby ruby-2.2.2

Which makes Ruby 2.2.2 the default Ruby. Then simply add a .ruby-version file with the Ruby version you would like (e.g ‘2.2.2’) for that directory and all directories inside it unless they specify their own .ruby-version. Easy huh!?

You’re rubies are now either in /opt/rubies or ~/.rubies.

Update RubyGems and install Rails

gem update --system

Now for Rails:

sudo gem install rails

Restart terminal and check your versions by:

ruby -v
rails -v

Update Homebrew and let’s get brewing!

Let’s update Homebrew and install some software to get you going; ImageMagic, Git and Postgres.

brew update
brew install ImageMagick
brew install git
brew install postgres

Then to start Postgres and on startup, run the lines it tells you to, mine were:

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Then create your initial db:

createdb

Then:

psql
CREATE ROLE postgres LOGIN CREATEDB;

to create your posters user and check it works ok (use CTRL Z to come out).

Code Editors

Finally you need a decent editor! Personally I use MacVim and sometimes TextMate 2.

Get TextMate 2 from here.

To install MacVim:

Get the latest snapshot from here and double click then move to your applications folder (or you can do ‘brew install macvim’).

Once installed, you’ll want to drag the ‘mvim’ file to your desktop, and then in terminal:

mv ~/Desktop/mvim /usr/local/bin

This allows you to use ‘mvim’ in the terminal.

Next you’ll want to use Janus, which can be installed by running this in terminal:

curl -Lo- https://bit.ly/janus-bootstrap | bash

That’s it! Tho, if you want to learn more about Vim, Janus or install a nice theme, check out this post