Installing Rails 3.1: Detailed (and current) instructions on how to install Rails 3.1 with advice and troubleshooting tips.
This is a guide for developers using the starter apps from the repository. Others may find it helpful as well.
Follow on Twitter for updates and timely Rails tips.
If you’re interested, see a discussion on Hacker News: .
What’s New
You can read more about how the building blocks of the Rails platform work together by reading the article . It explains the relationships among Ruby, RubyGems, Rails, Rake, Bundler, and gemfiles and offers some advice.
Rails 3.1
Rails 3.1.0 was released August 31, 2011. Eight release candidates were released beginning May 21, 2011. Rails 3.1 introduced the which enables proper organization of CSS and JavaScript. Other features include , default jQuery, reversible migrations, mountable engines, identity map, prepared statements, Rack::Cache on by default, forced SSL, role-based mass-assignment protection, has_secure_password, and custom serializers. See the for details. There’s a from Ryan Bates and a for all the details. Yehuda Katz explains . The best overview of Rails 3.1 is Michael Hartl’s in his Ruby on Rails Tutorial book.
What You Need to Know: The greatest impact for developers moving from Rails 3.0 to 3.1 is the new location for CSS and JavaScript files and changes to the application layout file. See the official for details.
Rake
Rake is the build tool for Ruby. Rake version 0.9.0 was released May 20, 2011. Rake 0.8.7 installs as part of Ruby 1.9.2. Many gems depend on Rake and conflicting dependencies can be a problem, especially since the release of Rake version 0.9.0 . For an explanation, see . If needed, you can specify an earlier version of Rake in your gemfile to force the use of the Rake version specified in your gemfile. It’s good practice to use the command bundle exec rake
instead of rake
so you’ll use the version of Rake specified in your gemfile (or a dependency specified in the Gemfile.lock file) instead of the default version. For example, instead of rake db:migrate
, run bundle exec rake db:migrate
.
What You Need to Know: Update Rake 0.8.7 to Rake 0.9.2 (or ) with gem update rake
before installing Rails 3.1. And use bundle exec rake
instead of rake
.
RubyGems
RubyGems is a package management framework for Ruby. RubyGems 1.8.10 was released August 27, 2011 and addresses a security vulnerability. With version 1.8.0 (released May 4, 2011), the RubyGems system gem began a series of rapid updates. Releases between 1.8.0 and 1.8.5 generated “noisy” deprecation warnings but most installed gems continued to work. RubyGems 1.8.5 eliminated most of the deprecation warnings. If you think a gem may be failing because of an incompatibility with the newest RubyGems implementation, you can troubleshoot by rolling back to an earlier RubyGems system gem with gem update --system 1.7.2
or gem update --system 1.3.7
.
What You Need to Know: Use gem update --system
to upgrade to the .
Update or Install?
If you already have Rails installed, you could run gem update rails
for the newest version of Rails. In a word: don’t.
You’ll be better served by using rvm, the , to create a new gemset for the new Rails version. Then you can switch back if necessary.
Installing Rails 3.1
Follow these instructions to set up Rails 3.1 as a platform for the or any other apps you may build.
Do You Ruby?
Ruby should be installed on your computer. The version doesn’t matter; you’ll install Ruby 1.9.2 using rvm.
Install or Update RVM
Use rvm, the , to manage your Rails versions and create a gemset specifically for each application you build. If you encounter conflicting gem dependencies, you can isolate the errors by creating different gemsets with rvm.
The rvm website explains .
If you already have rvm installed, update it to the latest version.
$ rvm get latest $ rvm reload $ rvm -v
Install Ruby 1.9.2
Check for the current . Ruby 1.9.2 patch level 290 was current when this was written.
If you don’t have it already, use rvm to install the recommended version of Ruby and make it your default:
$ rvm install ruby-1.9.2-p290 $ rvm --default use ruby-1.9.2-p290 $ ruby -v
RubyGems
The RubyGems package management system comes as part of a standard Ruby language installation.
What version of the RubyGems system is installed on your machine? Check with:
$ gem -v
Check for the . It should be version 1.8.10 or newer (version 1.8.10 resolves a security vulnerability).
Use gem update --system
to upgrade the RubyGems system.
See the article if you have problems with gem incompatibilities.
Create a Rails 3.1 Gemset
Create a default Rails 3.1 gemset. It’s advisable to create a new gemset for each application you build. But to get started, create just one new Rails 3.1 gemset as your default.
$ rvm ruby-1.9.2-p290@rails31 --create --default
To see a list of the gemsets you have installed:
$ rvm gemset list
And see a list of the gems included with the standard Ruby installation:
$ gem list
Update Rake
Update from Rake 0.8.7 (installed with Ruby 1.9.2) to Rake 0.9.2 (or ) before you install Rails 3.1.
$ gem update rake $ rake --version
Install Rails 3.1
Now you can install Rails 3.1.
Check for the .
If you want the most recent stable release:
$ gem install rails $ rails -v
If you want the newest beta version or release candidate, you can install with --pre
.
$ gem install rails --pre $ rails -v
Or you can get a specific version (sometimes the newest version is broken).
For example, if you want the Rails 3.1 final release, install with --version=3.1.0
.
Or, as an alternative to --pre
, for the newest available version:
$ gem install rails -v ">=3.1.0" $ rails -v
Generate a Rails App
You can create a test application:
$ rails new testapp
Switch to the application root directory to examine and test what you’ve built.
$ cd testapp
Ubuntu Linux
For the Rails 3.1 release candidate, a JavaScript runtime is needed for Linux Ubuntu. It is not needed for Mac OS X or Windows. It will not be needed for the final release of Rails 3.1. Add this to your Gemfile:
gem 'therubyracer', '>= 0.8.2'
Quick Test
For a “smoke test” to see if everything runs, display a list of Rake tasks.
$ bundle exec rake -T
Remember, it’s good practice to run bundle exec rake
instead of rake
in case a gem specified in your gemfile (or a dependency in the Gemfile.lock file) relies on a version of Rake that’s different from the newest one you’ve installed.
More Information
See the for an introduction to building and running a Rails app.
See a list of if you’re just getting started.
Get a Starter App
The starter apps from the repository provide good examples of Rails 3.1 apps.
Plus, by using one of these starter apps, you can minimize the effort needed to stay current with changing Rails and gem versions.
You can see an from the starter apps.
Starter Apps
Each app provides a set of useful, popular Rails gems integrated into a working application. Each example is known to work and can serve as your personal “reference implementation”. Each is an open source project. Dozens of developers use the apps, report problems as they arise, and propose solutions as GitHub issues. There is a tutorial for each one so there’s no mystery code.
Author | Starter App | Tutorial | App Template | Comments |
---|---|---|---|---|
Daniel Kehoe | Uses Devise for authentication with ActiveRecord and SQLite for a database | |||
Daniel Kehoe | Uses Devise for authentication with a MongoDB datastore | |||
Daniel Kehoe | Uses OmniAuth for authentication with a MongoDB datastore |
These starter apps were created with the gem.
Install from an Application Template
You can use the files in the repository to build the starter apps.
Use the "rails new app_name -m"
command to generate a Rails web application from a template.
You can add the -T -O
flags to skip Test::Unit files and Active Record files.
Rails 3 + Devise + RSpec + Cucumber
To build the “rails3-devise-rspec-cucumber” starter application, run the command:
$ rails new APP_NAME -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-devise-rspec-cucumber-template.rb -T
Use the -T
flag to skip Test::Unit files.
See the or to learn how to configure and run the application.
Rails 3 + Mongoid + Devise
To build the “rails3-mongoid-devise” starter application, run the command:
$ rails new APP_NAME -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-mongoid-devise-template.rb -T -O
Use the -T -O
flags to skip Test::Unit files and Active Record files.
See the or to learn how to configure and run the application.
Rails 3 + Mongoid + OmniAuth
To build the “rails3-mongoid-omniauth” starter application, run the command:
$ rails new APP_NAME -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-mongoid-omniauth-template.rb -T -O
Use the -T -O
flags to skip Test::Unit files and Active Record files.
See the or to learn how to configure and run the application.
Deploy to Heroku
Heroku provides low cost, easily configured Rails application hosting. For your convenience, here are instructions for .
Using the .rvmrc file for Project-Specific Gemsets
After you’ve created an rvm gemset that you’ll use for a project and begun to build the app, you can create an .rvmrc file in the application’s root directory. RVM recgonizes an .rvmrc file in a directory and loads the gemset specified inside.
Here’s how to create an .rvmrc file if you’re using a gemset named “ruby192@rails31”:
$ echo "rvm ruby192@rails31" > .rvmrc
Using an .rvmrc file means you’ll automatically be using the correct Rails and gem version when you run your application on your local machine. This works best if you create an rvm gemset specifically for your application.
Troubleshooting
Problems? Check the .
Problems with Rake
If you see:
The template ... could not be loaded. Error: You have already activated rake 0.8.7, but your Gemfile requires rake 0.9.x. Consider using bundle exec.
You must update the standard Ruby installation from Rake 0.8.7 to Rake 0.9.2 (or ) before using the application templates to generate a new Rails app.