Blog article

In this opportunity I’ll explain (as the title suggests) how to go from a brand new mac os x to running Rails tests.

Step 0, is to make sure that locale returns


(you’ll get some unexpected errors later on if not). To do so, you can either set the Language to one that Mac OS X sets UTF-8 by default, like United States from the System Preferences panel. Or, you can run

$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8

to achieve that.

Step 1, install Xcode.

Step 2, install osx-gcc-installer from

Step 3, So now you’re ready to install Homebrew, by doing:

$ /usr/bin/ruby -e "$(/usr/bin/curl -fksSL"

Now this is how to install some common libraries

Step 4, We need to first have git in order run the brew doctor, so $ brew install git

You can make sure that everything is ok by running $ brew doctor at any time. It should return ’Your system is raring to brew’ when in optimal conditions.

Step 5, now to install the rest of the libraries

$ brew install memcached mysql postgresql

Step 6, initializing the mysql and postgres databases must be done by doing

$ initdb /usr/local/var/postgres
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew
--prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

Step 7, I like having some aliases to load/unload mysql, postgres and memcached. To do so, you should add the following lines to your ~/.zshrc

alias memcached_load="launchctl load -w /usr/local/Cellar/memcached/1.4.13/homebrew.mxcl.memcached.plist"
alias memcached_unload="launchctl unload -w /usr/local/Cellar/memcached/1.4.13/homebrew.mxcl.memcached.plist"
alias mysql_load="launchctl load -w /usr/local/Cellar/mysql/5.5.20/homebrew.mxcl.mysql.plist"
alias mysql_unload="launchctl unload -w /usr/local/Cellar/mysql/5.5.20/homebrew.mxcl.mysql.plist"
alias postgres_load="launchctl load -w /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist"
alias postgres_unload="launchctl unload -w /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist"

Step 8, Now you’re good to go. Next we’ll install rbenv to easily switch between multiple versions of Ruby. You can also choose to use RVM or roll your own. $ brew install rbenv ruby-build

Step 9, Add

export PATH=$HOME/.rbenv/bin:$PATH
eval "$(rbenv init -)"

to your ~/.zshrc.

Step 10, now do the following to install ruby $ rbenv install 1.9.3-p125

Step 11, you need to $ rbenv global 1.9.3-p125 $ rbenv rehash

Step 12, Cool, so now we are good to go and setup Rails.

$ git clone
$ gem install bundler
$ rbenv rehash
$ cd rails
$ bundle

Step 13, now, from the Contributing to Rails Guide, you should

$ mysql_load
$ postgres_load
$ mysql -u root
mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
$ cd activerecord
$ rake mysql:build_databases
$ rake postgresql:build_databases

And that’s it!, we have Ruby, MySQL, PostgreSQL, Memcached, and everything needed to do some Rails development.

Step 14, we need to load Memcached for its needed for some tests by doing $ memcached_load

Step 15, and lastly, you can run Rails tests by doing $ rake at the top of the rails directory.

Everything should work just fine, or at least you should get the same results as the Rails CI.