Setting up your Ruby Toolset - mdoroudi/TraceHealth GitHub Wiki

Ruby development requires controlling Ruby versions and gemsets on a per-project basis. We use rbenv for switching Ruby versions and bundler for controlling gemsets.

Install rbenv and mysql

First, install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"

Then install rbenv and ruby-build

brew install rbenv        # Basic rbenv utility
brew install ruby-build   # Adds 'rbenv install' command

Install mysql if not already installed:

brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" \
  --datadir=/usr/local/var/mysql --tmpdir=/tmp

This StackOverflow answer has a good walk-through if you want to uninstall and reinstall MySQL.

Install Bundler

Install the bundler gem:

gem install bundler

I recommend configuring bundler to always install to vendor/bundle; you want gems installed locally to your project's directory, and not to your global bundler gemset:

bundle config path vendor/bundle

Installing the Rails app

Clone the TraceHealth Rails app:

git clone https://github.com/nogaleviner/TraceHealth.git
cd TraceHealth

Install the Ruby version and gems. From the TraceHealth/ directory, run:

rbenv install   # Skip if already installed
bundle install

You now have the proper Ruby version installed via rbenv, and all necessary gems installed locally to TraceHealth/vendor/. You can confirm this by:

rbenv version   # Display current ruby version
bundle show    # List all gems installed by bundler

Now whenever you want to execute a Ruby/Rails command, you must prepend it with bundle exec so bundler will pull all gems into the current Ruby environment. I recommend adding the be alias to your ~/.bashrc file to reduce typing:

echo "alias be='bundle exec'" >> ~/.bashrc

Run it!

Start a mysql instance:

mysqld_safe

Set up the database:

be rake db:create db:migrate db:seed db:test:clone

And run tests to make sure everything works:

be rake spec

Boom!