Ruby 2.1 and Rails 4.0 for Mac

From Ruby on Rails4.0 Guide

curl -L | bash -s stable --rails

In my case, failed twice.
One is home brew version.
To fix that, you need to update brew

brew update

One is gem fetch. I don’t know how to fix.
This commands install ruby2.1 and rails4.0 or other ralated gems

source ~/.rvm/scripts/rvm

I need to close terminal and open again.
Log says that sometimes reopening terminal is required.

Install rails

sudo gem install rails