ParsaLabs | Blog

A publication about the web and more.

Setting Up a Ruby on Rails (4) Development Environment on a Clean Mac OS X Installation

| Comments

First, install the command line tools:

  • Browse to Apple Developer Download Page and sign in with your apple ID.
  • In the list of packages, look for Command Line Tools (OS X Mountain Lion) for Xcode (or whatever your mac version happens to be at the time you are reading this).
  • Download the .dmg package, and install it by double-clicking on it and following the installation instructions.

Install homebrew:

  • Run the following command at a terminal prompt:
1
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  • Then run brew doctor in terminal to make sure everything is ok with your homebrew installation, in which case, you will see the “Your system is ready to brew” message. Don’t worry if there are any warnings, just read the description carefully, most of the time you will find useful suggestions. Follow them, and you will be fine. During my installation, I got a warning about an outdated version of Git, and as a remedy, homebrew suggested that I run brew install git which solved the problem. Running brew doctor again verified it, and I was good to go.

  • Finally, run brew update

Install Rbenv:

  • Run the following command at a terminal prompt:
1
brew install rbenv
  • You will need to configure your bash profile. You’ll only ever have to do this once. (in case you cannot find your bash profile in the home directory, simply create it by running touch ~/.bash_profile.
1
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Then:

1
source ~/.bash_profile
  • Install ruby-build and rbenv rehash gem using homebrew:
1
2
brew install rbenv-gem-rehash
brew install ruby-build

Note: to later update these installs, use upgrade instead of install.

At this point, we are pretty much done with rbenv installation.

Install Rubies:

  • Now, you can install different versions of ruby using the rbenv install command. For example, below we are going to install 3 versions of ruby:
1
2
3
rbenv install 1.9.3-p194
rbenv install 1.9.3-p429
rbenv install 2.0.0-p353
  • Run rbenv rehash. In fact you should run this every time you install a new version of ruby or when you install a gem that provides a command.

  • Set the 2.0 version as the global default (because it is the latest and greatest ruby, you should all use/prefer it over other versions):

1
rbenv global 2.0.0-p195
  • At this point you should spend some time reading rbenv command reference and get familiarised with different commands that rbenv provides for simple ruby version management. Highly recommended that you read the above link very carefully before moving on to the rest of this tutorial. however, here’s a summary of the most important commands:

rbenv local <VERSION> : will set the local project level version of ruby to the VERSION specified.
rbenv local : will report the local version of ruby currently being used.
rbenv versions : will report all ruby versions known to rbenv.
rbenv version : will report the currently active ruby version.
rbenv which irb : will show the full path to the executable that rbenv will invoke when you run the given command.

Install Gems:

  • Next, we will update to the latest Rubygems version:
1
gem update --system
  • Install the rails 4 gem:
1
gem install rails --version 4.0.0 --no-ri --no-rdoc
  • And other gems required for rails development:
1
gem install bundler foreman pg thin --no-rdoc --no-ri
  • Run rbenv rehash

And we are pretty much done with our basic rails 4 development environment :–)

To test things out:

To ensure everything is installed properly:

1
2
3
rails new my_first_app
cd my_first_app
rails server

and browse to http://0.0.0.0:3000/ in your favourite web browser. You should be able to see the infamous rails welcome page (as depicted below):

It worked! Yaaaay!

Comments