Install Rails 3.1 for the Rails Tutorial

Mark Berry September 27, 2011

I’ve been working through Michael Hartl’s Ruby on Rails Tutorial. I had some trouble in chapter 13 installing the released version of Rails 3.1.0, so I thought I would post what worked for me.

When I tried to follow section 13.1.1 Installing and configuring Rails 3.1, I got errors about an older Ruby version, then about a missing ZenTest gem. I tried to follow the advice in the messages to update ruby and to run bundle install. But even after that, rails –v told me that I was still at Rails 3.0.9.

My main mistake was trying to run install Rails 3.1 in the existing sample_app folder, which includes a gemfile specifying older gem versions, including Rails 3.0.9.

I reverted my Ubuntu virtual machine and started over. Then, loosely following Read This Before Installing Rails 3.1, I got Rails 3.1. installed as follows.

# IMPORTANT:  go to root of Home folder to avoid
# using project-specific gemfile
cd ~

# Upgrade RVM from 1.6.20 to 1.8.4
rvm -v
rvm get latest
rvm reload
rvm -v

# Check installed rubies and default ruby
rvm list
# "=> ruby-1.9.2-p180"
ruby -v
# "ruby 1.9.2p180 ..."

# Check currently available version of Ruby
rvm list known
# shows 1.9.2[-p290]

# Check your current gemsets in case you want
# to follow their naming convention later
rvm gemset list

Update April 27, 2012 Installing Ruby 1.9.3 failed until I first installed LIBTOOL. See this blog post.

# Install current Ruby (takes a while to compile)
rvm install ruby-1.9.2

# Check installed rubies and default ruby
rvm list
ruby -v

# Change default to latest version and check again
rvm --default use ruby-1.9.2-p290
rvm list
ruby -v

# Make sure RubyGems is >= 1.8.10 (security fix)
gem -v

Update September 11, 2012 The remainder of this section (up to “Back to the Tutorial”) is optional. It will give you a default installation of Rails not linked to a project.

# Check gemsets, create a default Rails 3.1 gemset, check again
rvm gemset list
rvm ruby-1.9.2@rails31 --create --default
rvm gemset list

# Check and update Rake 0.8.7 to 0.9.2 or newer
rake --version
gem update rake
rake --version

# NOW you can check and install Rails 3.1

rails –v
# "The program 'rails' is currently not installed."
gem install rails --version=3.1.0
# "file 'lib' not found" messages on ri and RDoc
# documentation packages for rails-3.1.0, but seems
# to work anyway
rails -v
# "Rails 3.1.0"

Back to the Tutorial

Now you are ready to work through the Ruby on Rails Tutorial section 13.1.1 Installing and configuring Rails 3.1. A few additions are necessary for things to go smoothly.

# Create a project-specific gemset and make it the default
rvm --create use 1.9.2@rails31_tutorial
rvm --default use 1.9.2@rails31_tutorial

# Install Rails 3.1 into to the project-specific gemset
gem install rails --version=3.1.0
rails -v

# Use "rails new" to create an app skeleton
cd ~/rails_projects
rails new sample_app_31

# bundle install won’t work until you are in project folder
cd sample_app_31

# Copy the updated gemfile below, then install/update gems
bundle install

Update January 10, 2012:  I followed most of the above instructions to update to Ruby 1.9.3 and Rails 3.1.3. However because I was updating an existing project, after updating version numbers in my gemfile loosely following this example, bundle install failed with messages about rspec-rails depending on a version of railties that was not available. It turns out bundle was trying to use old versions of some gems based on gemfile.lock. So I ran bundle update, which ignores gemfile.lock and re-loads all gems.

Gemfile Updates

Things are obviously moving fast in Rails 3.1 development. I made some changes to my gemfile to get things running right. Here is the entire file, with comments about the changes:

source 'http://rubygems.org'

gem 'rails', '3.1.0'
# 9/28/2011 Add 'therubyracer' to resolve 
#           "Could not find a JavaScript runtime."
#           See http://stackoverflow.com/questions/6282307
gem 'therubyracer'

gem 'gravatar_image_tag', '1.0.0.pre2'
# 9/28/2011:  will_paginate 3.0.2 released 9/27/2011.
#             "kludge" patch in tutorial section 13.1.3
#             no longer needed
# gem 'will_paginate', '3.0.pre2'
gem 'will_paginate', '3.0.2'
gem 'sqlite3', '1.3.4'

# Asset template engines
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-script'
gem 'uglifier'

gem 'jquery-rails'

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate', '2.4.0'
  gem 'faker', '0.3.1'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.1'
  # 9/28/2011:  spork 0.9.0.rc9 from 6/30/2011 gets rid of
  #             some deprecation warnings at startup
  # gem 'spork', '0.9.0.rc5'
  gem 'spork', '0.9.0.rc9'
  gem 'factory_girl_rails', '1.0'

  # 9/28/2011:  Add autotest (from section 3.5 exercises)
  gem 'autotest', '4.4.6'
  gem 'autotest-rails-pure', '4.1.2'
  # gem 'autotest-fsevent', '0.2.4' # Mac OS X only
  gem 'autotest-growl', '0.2.9'
end


Leave a Reply





*