title: rbenv: Surviving without gemsets
body: <p><strong>TL;DR</strong></p>
  
  <ul>
  <li>Don't bother with gemsets; multiple versions of a gem may be installed concurrently.</li>
  <li>When necessary, specify which version to execute using <code>$ gem-based-binary _version_ args</code> notation.</li>
  <li>Use <code>bundle exec</code> when you have a Gemfile specifying the version.</li>
  </ul>
  
  <pre class="lang-ruby prettyprint-override"><code>gem install rails -v 3.2.13
  rails _3.2.13_ new Project2
  cd Project2
  bundle exec rails server
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE:</strong> 2015-06-04</p>
  
  <p>I wrote this question three years ago.  Partly, it was based on a false assumption, and partly the situation has changed since then.  With appreciation to @indirect for his original answer, I want to call attention to @kelvin's newer (less upvoted) answer, summarized above.</p>
  
  <p>My false assumption: Only a single version of a gem could be installed at a time, hence the need for gemsets to isolate the namespace.  Not true.  Multiple versions of a gem may be installed concurrently.  The most recent one will be used when invoked from a command line, unless you have a Gemfile specifying the version constraints and invoke the command via <code>bundle exec</code>, or specify the version as its first argument.</p>
  
  <p>See also <a href="https://stackoverflow.com/a/4062229/577438">How can I call an older version of a gem from the commandline?</a> re: the underscore-version notation.</p>
  
  <hr>
  
  <p><strong>Original question:</strong></p>
  
  <p>I have multiple projects going on using different versions of Rails.  I have a workflow (described below) for creating projects using specific versions of rails, and keeping the projects isolated from each other.  I'd like to experiment with other workflows, in particular, using rbenv instead of RVM, but it's not clear how to do so.</p>
  
  <p><strong>QUESTION:</strong>  What is the <strong>best current practice</strong> for creating multiple rails projects, each using a different version of rails, when making use of <strong>rbenv</strong> and <strong>bundler</strong>, as opposed to rbenv-gemset or rvm?</p>
  
  <p><strong>USE CASE:</strong>  I have two rails projects, called ProjectA and ProjectB.  ProjectA is developed using one version of rails ("RailsA"), whereas ProjectB uses a different version ("RailsB").  How do I manage having both versions installed?</p>
  
  <p><strong>THE GEMSETS APPROACH:</strong>  When I first started with Rails development, I used <a href="http://beginrescueend.com/" rel="nofollow noreferrer">RVM</a>.  In addition to supporting multiple, concurrent installations of ruby, RVM supports having multiple <a href="http://beginrescueend.com/gemsets/basics/" rel="nofollow noreferrer">Named Gem Sets</a>.  Each project has its own independent collection of gems (including rails itself) called a gemset:</p>
  
  <pre class="lang-bash prettyprint-override"><code>rvm gemset create RailsA
  rvm gemset use RailsA
  # RailsA.  Note: My question is not version-specific.
  gem install rails --version 3.0
  rails new ProjectA
  cd ProjectA
  rvm --rvmrc use `rvm current`
  vi Gemfile
  bundle install
  cd ..
  ## Now do the same for ProjectB
  rvm gemset create RailsB
  rvm gemset use RailsB
  gem install rails --version 3.2
  rails new ProjectB
  cd ProjectB
  rvm --rvmrc use `rvm current`
  vi Gemfile
  bundle install
  </code></pre>
  
  <p>Note: The very <strong>creation</strong> of the project folders should be done (IMHO) by a <code>rails new</code> command using the <em>desired version</em> of rails, since the skeleton files change from version to version.  (Perhaps I should revisit this premise?)</p>
  
  <p><strong>THE BUNDLER APPROACH:</strong> I've been playing with using <a href="https://github.com/sstephenson/rbenv" rel="nofollow noreferrer">rbenv</a> instead of RVM, but I don't understand the workflow as clearly.  In the <a href="https://github.com/sstephenson/rbenv" rel="nofollow noreferrer">README.md</a>, Sam Stephenson writes that "rbenv does not ... manage gemsets.  Bundler is a better way to manage application dependencies."  There is a plugin (<a href="https://github.com/jamis/rbenv-gemset" rel="nofollow noreferrer">rbenv-gemset</a>) for getting the same results as rvm's gemsets, but Sam clearly favors using Bundler instead.  Unfortunately, he doesn't elaborate on what the workflow would look like.  Even the <a href="http://gembundler.com/" rel="nofollow noreferrer">Bundler</a> website doesn't explicitly connect all the dots of how to isolate one project from another.  Several <a href="http://quickleft.com/blog/manage-rubies-with-rbenv" rel="nofollow noreferrer">blogs</a> <a href="http://snippets.aktagon.com/snippets/532-How-to-migrate-from-rvm-to-rbenv" rel="nofollow noreferrer">and</a> <a href="https://gist.github.com/1384279" rel="nofollow noreferrer">gists</a> come to the rescue, suggesting the following <code>~/.bundle/config</code> file:</p>
  
  <pre><code>---
  BUNDLE_PATH: vendor/bundle
  </code></pre>
  
  <p>(BTW, I'm not sure what the "---" is about.  The docs make no mention of it and it doesn't seem to make a difference.)</p>
  
  <p>This effectively gives each rails project its own gemset, storing the gems in ProjectX/vendor/bundle/.  In fact, rails itself will be (re-)installed there, making the project completely independent of the rest of my environment, once I run <code>bundle install</code>.</p>
  
  <p><strong>But the <em>elephant in the room</em> is the chicken-and-egg problem of creating the rails project folder in the <em>first place!!</em></strong>   In order to create the ProjectA folder using RailsA, I need to install rails (and its numerous dependencies) <em>first</em>.   But when I want to create ProjectB, I must then switch to using RailsB.  Without gemsets, I must do some serious upgrading/downgrading.  Not cool.</p>
  
  <p>A possible solution is simply not to worry about what version of rails I use to create the ProjectX folder.  If I then use rails 3.0 to create a 3.2 project, I could just manually create the app/assets tree.  But that just irks me.  Ain't there a better way?</p>