-
Notifications
You must be signed in to change notification settings - Fork 0
installing rails
Last updated 1 March 2012
Installing Rails 3.2.2: Detailed (and current) instructions on how to install the latest release of Rails 3.2 with advice and troubleshooting tips.
This is a guide for developers using the starter apps from the Rails Apps repository. Others may find it helpful as well.
See a list of recommended resources for Rails.
Follow @rails_apps on Twitter for updates and timely Rails tips.
You can read more about how the building blocks of the Rails platform work together by reading the article Managing Rails Versions and Gems. It explains the relationships among Ruby, RubyGems, Rails, Rake, Bundler, and gemfiles and offers some advice.
Rails 3.2.2 was released March 1, 2012 with some minor bug fixes plus two important security fixes (see the Rails 3.2.2 Announcement). Rails 3.2.1 was released January 26, 2012 with some minor fixes (see Ruby on Rails v3.2.1 Changelogs).
Rails 3.2 was released January 20, 2012. Improvements include faster execution in development mode. The speed of resolving routes also improved. There are many tiny (but helpful) improvements throughout the framework. Rails 3.2 deprecates plugins (Rails 4.0 will remove them completely) so find Ruby gems to replace any plugins you may still be using. You can use Ruby 1.8.7 but consider moving to Ruby 1.9.3 (the current stable and recommended Ruby version) because Rails 4.0 will require Ruby 1.9.3. See the Rails 3.2.0 Announcement and Ruby on Rails 3.2 Release Notes (with upgrade instructions). There’s a Railscast from Ryan Bates titiled Upgrading to Rails 3.2. Michael Hartl’s popular Ruby on Rails Tutorial book has been rewritten to cover Rails 3.2 with improved treatment of RSpec and Cucumber (Ruby on Rails Tutorial Version 3.2). Finally, José Valim highlights his Five Favorite ‘Hidden’ features in Rails 3.2.
What You Need to Know: Upgrading from Rails 3.1 to Rails 3.2 is easy and yields faster performance (especially in development mode). You may run into issues if your application has routing complexities (the routing engine has changed). For an older application, upgrade to Rails 3.1 before upgrading to Rails 3.2.
Rails 3.1.0 was released August 31, 2011. Eight release candidates were released beginning May 21, 2011. Rails 3.1 introduced the asset pipeline which enables proper organization of CSS and JavaScript. Other features include HTTP streaming, 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 Rails 3.1 release candidate announcement for details. There’s a Rails 3.1 Overview from Ryan Bates and a changelog for all the details. Yehuda Katz explains What’s Up With All These Changes in Rails?. The best overview of Rails 3.1 is Michael Hartl’s chapter on Rails 3.1 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 Rails 3.1 Asset Pipeline guide for details.
RubyGems is a package management framework for Ruby. RubyGems 1.8.18 was released March 12, 2012. RubyGems installs as part of Ruby 1.9.3.
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 newest RubyGems system gem.
Rake is the build tool for Ruby. Rake version 0.9.2 was released on June 5, 2011 and followed by Rake version 0.9.2.2 on October 22, 2011. Rake 0.9.2 installs as part of Ruby 1.9.3.
Many gems depend on Rake and conflicting dependencies can be a problem, especially since the release of Rake version 0.9.0 (May 20, 2011). For an explanation, see David Chelimsky’s blog post. 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: Make sure you are using Rake 0.9.2.2 (or newer) with gem update rake
before installing Rails 3.2. And use bundle exec rake
instead of rake
. If you don’t like combining bundle exec
with rake
, see suggestions for rvm and bundler integration.
Bundler version 1.1.0 was released March 7, 2012 and is significantly faster than previous versions.
What You Need to Know: Use gem update bundler
to upgrade to the newest Bundler gem.
Follow these instructions to set up Rails 3.2 as a platform for the Rails example apps or any other apps you may build.
Recommended: You should use rvm, the Ruby Version Manager, to create a new gemset and install the new Rails version. Then you can switch between versions if necessary.
Not recommended: If you have an older version of Rails installed, it is possible to run gem update rails
to get the newest version of Rails. But it is well worth the effort to install and use rvm to manage Rails versions.
You’ll need to install Ruby 1.9.3 on your computer using rvm. Ruby may already be installed on your computer (Mac OS X 10.7 comes with Ruby 1.8.7 preinstalled). You don’t need to remove an earlier version of Ruby if you install Ruby 1.9.3 using rvm. If you already have Ruby 1.9.3 but are not using rvm, I recommend installing rvm and a fresh version of Ruby 1.9.3 (detailed instructions below).
Sam Stephenson offers an alternative to rvm named rbenv that lets you switch between multiple versions of Ruby. With Jamis Buck’s rbenv-gemset you can switch between gemsets as well. The utilities rbenv and rbenv-gemset are less “magic” than Wayne Seguin’s rvm and can be useful if you encounter issues with rvm. Here are notes for installing Ruby on MacOS X 10.7.3 with XCode 4.3 and rbenv.
You need a C language compiler to install Ruby and any gems that require native extensions. Linux operating systems include the necessary gcc compiler. Default installations of Windows or Mac OS X don’t include gcc.
To prepare a Mac for installation of Ruby 1.9.3, you could install XCode for free from the Mac App Store to get development tools including a C language compiler. XCode includes clang, a gcc replacement based on the LLVM compiler project. XCode is a huge tool suite (1.35GB) and may take many minutes to download. Therefore, unless you are going to use XCode for other reasons, I recommend using Kenneth Reitz’s OSX GCC Installer to install the gcc compiler before attempting to install Ruby. See a guide to Installing Rails on Macintosh from Railsbridge Installfest for step-by-step instructions.
To install Ruby 1.9.3 on Ubuntu Linux, there are several useful guides:
- Installing Rails on Ubuntu from Railsbridge Installfest
- Mircea Goia’s tutorial
- Joshua Frye’s Rails Ready setup script
- Ryan Bigg’s tutorial
- Peter Cooper’s screencast
Note: You can develop with Rails on Windows but be aware that most developers use Mac OS X or Ubuntu to develop Rails applications. Some gems requiring native extensions may be difficult to install on Windows. Developers (including The Code Shop) are working to improve the speed of Ruby 1.9.3 on Windows (see a benchmark) as earlier versions were frustratingly slow.
To prepare Windows for installation of Ruby 1.9.3, start with RailsInstaller from Engine Yard. RailsInstaller includes a “DevKit”: which installs gcc and other Unix build tools. At the time this was written, RailsInstaller included Ruby 1.9.2-p290 and Rails 3.1.1. A version with Ruby 1.9.3 and Rails 3.2 should be out soon. In the meantime, you can use Ruby Installer to upgrade Ruby after running RailsInstaller. See a guide to Installing Rails on Windows from Railsbridge Installfest for step-by-step instructions. On Windows, use Pik for services similar to rvm.
Use rvm, the Ruby Version Manager, 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 how to install rvm.
If you have an older version of Ruby installed you don’t need to remove it. Any older Ruby and Rails versions will remain on your system and the rvm versions will take precedence. Rvm will leave your system version of Ruby untouched and use your shell to intercept any calls to Ruby.
If you already have rvm installed, update it to the latest version.
$ rvm get latest $ rvm reload $ rvm -v
Check for the current recommended version of Ruby. Ruby 1.9.3 patch level 125 was current when this was written. There are other Ruby interpreters (REE from Phusion, JRuby, Rubinius, MagLev, and MacRuby) but Ruby 1.9.3 is your best choice for most Rails application development.
Check for rvm installation notes for your operating system version:
$ rvm requirements
Use rvm to install the recommended version of Ruby and make it your default:
$ rvm install ruby-1.9.3-p125 $ rvm --default use ruby-1.9.3-p125 $ ruby -v
Note: On a Mac, users with Xcode 4.2 encountered issues installing Ruby with rvm because XCode 4.2 doesn’t use the standard gcc compiler. If you encounter this issue, use Kenneth Reitz’s OSX GCC Installer to install the gcc compiler.
Note: Installing Ruby 1.9.3-p125 on Mac OS X 10.7.3 with Xcode 4.2.1 requires the following command line switch to succeed: rvm install 1.9.3-p125 --with-gcc=clang
.
Note: Have you used rvm to install Ruby 1.9.3-p125 on Mac OS X 10.7.3? Did you use Kenneth Reitz’s “OSX GCC Installer”? Or did you use Xcode 4.3? Did you need to add a command line switch to rvm such as --with-gcc=clang
to succeed? Please leave a comment below.
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 newest version of RubyGems. It should be version 1.8.17 or newer.
Use gem update --system
to upgrade the RubyGems system.
See the article Managing Rails Versions and Gems if you have problems with gem incompatibilities.
Only two gems are installed with Ruby 1.9.3. See what you have with gem list
:
- bundler
- rake
Ruby 1.9.3 includes Rake version 0.9.2. Rake version 0.9.2.2 was current when this was written.
Update to the newest version of Rake before you install Rails 3.2.
$ gem update rake $ rake --version
Create a default Rails 3.2 gemset. It’s advisable to create a new gemset for each application you build. But to get started, create just one new Rails 3.2 gemset as your default.
$ rvm ruby-1.9.3-p125@rails32 --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
When you create a new gemset, bundler will be the only gem installed. Each gemset starts with a clean slate. You will have to install Rails and any other gems you need.
Bundler version 1.1.0 was released March 7, 2012 and is significantly faster than previous versions.
Update to the newest version of Bundler before you install Rails 3.2.
$ gem update bundler $ bundle --version
Now you can install Rails 3.2.2.
Check for the current version of Rails.
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, as an alternative to --pre
, for the newest version:
$ gem install rails -v ">=3.2.2" $ rails -v
Or you can get a specific version (just in case the newest version is broken).
For example, if you want the Rails 3.2.0 release, install with --version=3.2.0
.
Since Rails 3.1, a JavaScript runtime has been needed for development on Ubuntu Linux. It is not needed for Mac OS X or Windows.
For development on Linux Ubuntu, it is best to install the Node.js server-side JavaScript environment:
sudo apt-get install nodejs
and set it in your $PATH
.
If you don’t install Node.js, you’ll need to add this to the Gemfile for each Rails application you build:
gem 'therubyracer'
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
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. If you don’t like combining bundle exec
with rake
, see suggestions for rvm and bundler integration.
See a list of recommended resources for Rails if you’re just getting started.
- Recommended Resources for Rails
- Example Gemfiles for Rails 3.2
- Using Git with Rails
- Rails Default Application Layout for HTML5
The starter apps from the Rails Apps repository provide good examples of Rails apps.
Plus, by using one of these starter apps, you can minimize the effort needed to stay current with changing Rails and gem versions.
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 | Devise, RSpec, Cucumber | Tutorial | App Template | Uses Devise for authentication with ActiveRecord and SQLite for a database |
Daniel Kehoe | Devise, Mongoid | Tutorial | App Template | Uses Devise for authentication with a MongoDB datastore |
Daniel Kehoe | OmniAuth, Mongoid | Tutorial | App Template | OmniAuth for authentication with a MongoDB datastore |
Daniel Kehoe | Subdomains, Devise, Mongoid | Tutorial | App Template | Basecamp-style subdomains with Devise and MongoDB |
These starter apps were created with the Rails Apps Composer gem.
You can use the files in the Rails Application Templates repository to build the starter apps.
Use the "rails new myapp -m"
command to generate a Rails web application from a template.
You can add the -T
flags to skip Test::Unit if you are using RSpec.
You can add the -O
flags to skip Active Record if you are using a NoSQL datastore such as MongoDB.
See the README or tutorial to learn how to install, configure and run the starter application.
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 “ruby-1.9.3-p125@rails32”:
$ echo "rvm ruby-1.9.3-p125@rails32" > .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.
Your best source for help with problems is Stack Overflow. Your issue may have been encountered and addressed by others.
You can also try Rails Hotline, a free telephone hotline for Rails help staffed by volunteers.
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.
If you are using Ruby 1.9.2, you must update the standard Ruby installation from Rake 0.8.7 to Rake 0.9.2 (or newer) before using the application templates to generate a new Rails app. It’s advisable to update to Ruby 1.9.3 which will provide Rake 0.9.2.
Are you getting an error “OpenSSL certificate verify failed” when you try to generate a new Rails app from an application template? See suggestions to resolve the error Certificate Verify Failed.