How can I install Ruby on Rails 3 on OSX?

31,474

Solution 1

First you need to install RVM, then the latest version of Ruby. Next you'll set that version of Ruby as the default. Finally, you'll install Rails b3.

Install RVM (http://rvm.beginrescueend.com/rvm/install/):

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Install the latest Ruby (http://rvm.beginrescueend.com/rubies/installing/):

rvm install ruby-head

You can check which versions you now have installed with:

rvm list

Set the latest version of Ruby as default (replace 'ruby-1.9.2-head' with desired version):

rvm ruby-1.9.2-head --default

Make sure things are up to day, then install the Rails beta:

gem update --system
gem install rails --pre

You may have to install some gem dependencies before Rails will install.

Solution 2

To easily setup Rails 3 on osx machine the only thing you need to do is follow this brilliant (as always) Railscast, here for the transcription

You can also see comments to check for problems and eventually solutions.

Solution 3

You should use rvm as others have said to manage multiple installations of Ruby and Ruby gems. (If you go that way, take the time to read rvm's documentation carefully.)

However, you should also get comfortable figuring out what version of Ruby your shell is seeing as the default and why. It sounds to me like your $PATH variable may not be properly updated. The $PATH variable is what determines which Ruby interpreter or gem command is the first seen, if you have more than one installed (as you now do). MacPorts will install new binaries into /opt/local/bin by default, and it should also alter your $PATH so that /opt/local/bin precedes /usr/bin (which is where Apple's out of the box Ruby lives).

I suspect that when you did sudo gem install, you were using /usr/bin/gem (which is the gem installer for /usr/bin/ruby rather than /opt/local/bin/gem (which would be the installer for MacPort's Ruby).

Check the output of echo $PATH, which ruby and which gem to see what's going on.

Solution 4

I would strongly recommend using RVM (Ruby Version Manager) to keep your Rails 3 separate from your Rails 2. (One example of Rails 2 conflicting with Rails 3: when you go to the command line to generate a Rails app, will it generate a Rails 2 app or a Rails 3 app? RVM allows you to keep them separate.)

Also, the latest Ruby 1.8.7 will probably not work with Rails 3, so you have to use an earlier patchlevel (248 works for me). Details are here: http://techiferous.com/2010/02/installing-rails-3-beta-with-rvm-and-ruby-1-8-7/

Solution 5

You may have two different versions of Ruby installed. Try "gem env" or "sudo gem env" and see which version of Ruby it says you have.

Remove the older one if you have two installed. If all else fails, upgrade to 1.9.x, I believe it is recommended for Rails 3 anyway.

Share:
31,474
Oluf Nielsen
Author by

Oluf Nielsen

Updated on May 12, 2020

Comments

  • Oluf Nielsen
    Oluf Nielsen almost 4 years

    I got a White Macbook and I have to go to a conference in 10 hours but I'm having a lot of problems.

    First, I wanted to have Rails 3, so I used MacPorts to install Ruby 1.8.7. It worked well ;) Then I was thinking I should install Rails 3, but no, no! It says:

    $ sudo gem install rails --pre
    
    ERROR: Error installing rails:
    
    
                activesupport requires Ruby version >= 1.8.7.
    

    What should I do? I already have 1.8.7!