Andrew Cox

Setting up a fresh Rails 3.1 project safely

So you want to start experimenting with some of the great new Rails 3.1 features like the new asset pipeline? Follow these instructions and you’ll stay out of trouble.

If you haven’t already, install rvm. Then fire up Terminal and follow these simple steps:

Make sure rvm is up-to-date:

$ rvm get head
$ rvm reload

Get the latest Ruby (1.9.2p180 is recommended for Rails 3.1):

$ rvm install 1.9.2
$ rvm 1.9.2

Get the latest Rails 3.1rc:

$ gem install rails -v ">=3.1.0rc"

Start a new Rails project:

$ rails new rails3play
$ cd rails3play

Set up a new git repository (optional):

$ git init

Create a new rvm project gemset:

$ rvm --rvmrc --create use 1.9.2@rails3play

This will create a new gemset and project .rvmrc file. Edit the .rvmrc file and uncomment the line in the bundler section at the bottom to add ./bin to your $PATH.

Note: rvm will only add this directory to your path when you’re within the project directory, so no worries about it messing up other stuff.

# If you use bundler and would like to run bundle each time you enter the
# directory, you can uncomment the following code.
export PATH="./bin:$PATH"

This is an important step based on the comments from Yehuda’s blog post about why you should always use bundle exec. Read the post and comments if you want all the background, but essentially this allows you to run executables like rake instead of bundle exec rake and know that you are running the correct version of rake based on properly-resolved Bundler dependencies.

Now you need to leave and re-enter your project’s directory for the new .rvmrc settings to apply:

$ cd ..
$ cd rails3play

Next, run bundle install with the --binstubs flag to create local executable wrappers:

$ bundle install --binstubs

You should now have a new Rails 3.1 project with safe executable gems that respect your Gemfile. Oh, and if you’re using using git:

$ git add .
$ git commit -m "Initial commit"

The conventional wisdom is that you should be checking in your .rvmrc, Gemfile.lock and the new bin directory, so don’t worry about adding anything to .gitignore.

So that’s that’s it! Go make something cool! If you run into any problems, hit me up on twitter