Skip to content

Setting up development environment

chaoran edited this page Aug 30, 2012 · 9 revisions

Install Xcode

Before anything starts, install Xcode through your Mac's App Store, or if you have already installed it, update to its latest version. But you will not use Xcode for Rails development. All you need is just its Command Line Tools. Open Xcode, from its menu, go to Xcode -> Preferences -> Downloads -> Components and install the Command Line Tools.

Install Homebrew

Homebrew is THE MOST AWESOME package manager to install everything on your MAC OS X. You should install everything through Homebrew. Please follow instructions on its home page to install Homebrew. After installation, please run brew doctor and brew update. brew doctor will probably tell you to include /usr/local/bin before your PATH. Please do that!

Install Rails

With Homebrew, you should be able to install rails with just one command:

$ brew install rails

Install PostgreSQL

Follow steps from here: SETTING UP POSTGRESQL FOR RUBY ON RAILS DEVELOPMENT ON OS X

Basically, what you need to do is:

$ brew install postgresql

Then, initialize it with:

$ initdb /usr/local/var/postgres

Do this to automatically load postgresql when your machine starts:

$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

Create a user for your rails project to use:

$ createuser [username] # I suggest you use project's name
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n

Note: remember to allow the created user to have the ability to create databases, otherwise the command rake db:create will not work.

Last thing, install pg gem:

env ARCHFLAGS="-arch x86_64" gem install pg

At this point, you should be able to create your db with the command rake db:create. Done!