The easiest way is to install XCode Command Line tools and then install ruby 2 via rvm then install rails 4 via gem.
- Install XCode Command lines tools
- rvm install ruby-2.0.0
- gem install rails
Update rvm by running rvm get head
You may face the below error if you dont install XCode Command line tools but try to install rails
Building native extensions. This could take a while…
ERROR: Error installing atomic:
ERROR: Failed to build gem native extension.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
/Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:434:in `try_do’: The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:519:in `try_link0′
from /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:817:in `try_run’
from extconf.rb:26:in `
Gem files will remain installed in /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/atomic-1.1.14 for inspection.
Results logged to /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/atomic-1.1.14/ext/gem_make.out
basically atomic gem expects you to have developer tools like gcc 4.2 which you can install view brew or simply install XCode command like tools, reinstall ruby via rvm and then install rails.