New Rails Project using RVM

October 12, 2010

This is my approach for creating a new rails projects using rvm (and git). What I’m trying to do here is ensure that the repository contains everything required for a developer to work and has minimal environmental pre-conditions.

The point of this is that if you get this repository you should only need to do the following to be able to start work on it.

  1. cd into the project, trust .rvmrc and do whatever rvm tells you to do to get your ruby installed, and the project gemset created.

  2. cd out and in again and install bundler

     ➥  cd ..
     ➥  cd project
     gem install bundler
     Successfully installed bundler-1.0.2
     1 gem installed
  3. run bundle install


  1. you have rvm installed

     ➥  which rvm
  2. you have the ruby you want to use

     ➥  rvm list 
     rvm rubies
        ruby-1.8.7-p249 [ x86_64 ]
     => ruby-1.8.7-p302 [ x86_64 ]
        ruby-1.9.2-p0 [ x86_64 ]

    here I am going to using 1.8.7-p302

Getting Started

We will create a new rails project in Sites/rn. So we will start from above

    [andy@airy-un ~/Sites] 
    ➥  rvm use 1.8.7-p302
    Using /Users/andy/.rvm/gems/ruby-1.8.7-p302
    [andy@airy-un ~/Sites] 
    ➥  gem list --local

    *** LOCAL GEMS ***

    rake (0.8.7)

Now create the directory and the .rvmrc, note how we are going to create a gemset specific to the project.

    [andy@airy-un ~/Sites] 
    ➥  mkdir rn
    ➥  echo rvm 1.8.7-p302@rn > rn/.rvmrc
    ➥  cat rn/.rvmrc
    rvm 1.8.7-p302@rn

Now cd into the project, trust .rvmrc and create the gemset

    [andy@airy-un ~/Sites] 
    ➥  cd rn

      RVM has encountered a not yet trusted .rvmrc file in the
      current working directory which contains the following code:

    rvm 1.8.7-p302@rn

      Trusting an .rvmrc file means that whenever you cd into the
      directory RVM will excecute this .rvmrc script in your shell

      Do you wish to trust this .rvmrc from now on?
      (y for yes, n for no) > y
    Gemset 'rn' does not exist, rvm gemset create 'rn' first.
    [andy@airy-un ~/Sites/rn] 
    ➥  rvm gemset create 'rn'
    'rn' gemset created (/Users/andy/.rvm/gems/ruby-1.8.7-p302@rn).

we can check we are using the gemset with rvm info. This displays loads of stuff which I’ve snipped

    ➥  rvm info


Now we create our Gemfile. Your Gemfile should look like

source ''
gem 'rails'

then install bundler and use it to install our gems.

    [andy@airy-un ~/Sites/rn] 
    ➥  gem install bundler
    ➥  bundle install
    Fetching source index for
    Installing rake (0.8.7) 
    Installing abstract (1.0.0) 
    Installing activesupport (3.0.0) 
    Installing builder (2.1.2) 
    Installing i18n (0.4.1) 
    Installing activemodel (3.0.0) 
    Installing erubis (2.6.6) 
    Installing rack (1.2.1) 
    Installing rack-mount (0.6.13) 
    Installing rack-test (0.5.6) 
    Installing tzinfo (0.3.23) 
    Installing actionpack (3.0.0) 
    Installing mime-types (1.16) 
    Installing polyglot (0.3.1) 
    Installing treetop (1.4.8) 
    Installing mail (2.2.7) 
    Installing actionmailer (3.0.0) 
    Installing arel (1.0.1) 
    Installing activerecord (3.0.0) 
    Installing activeresource (3.0.0) 
    Using bundler (1.0.2) 
    Installing thor (0.14.3) 
    Installing railties (3.0.0) 
    Installing rails (3.0.0) 
    Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

    Your bundle was installed to `/Users/andy/.rvm/gems/ruby-1.8.7-p302@rn`

Now we can run rails new to create our new project.

    [andy@airy-un ~/Sites/rn] 
            ➥  rails new .
                  create  README
                  create  Rakefile
                  create  .gitignore
                conflict  Gemfile
            Overwrite /Users/andy/Sites/rn/Gemfile? (enter "h" for help) [Ynaqdh]

we get a conflict here, but thats fine as our Gemfile is only there to get us started, so we can overwrite it.

    Overwrite /Users/andy/Sites/rn/Gemfile? (enter "h" for help) [Ynaqdh] Y
           force  Gemfile
          create  app
          create  vendor/plugins/.gitkeep

Using Git in this process

There are a number of ways to use GIT with this process. Personally I would do an init before creating the .rvmrc, and then a number of commits along the way documenting the project setup. However you could just run an init, add and commit at the end of the process