Skip to main content

Running multiple Rails versions

Rails • Asked by Jiri Prochazka

Hi guys (and ladies if any),

I have installed Rails with rbenv (recommended), but now because of significant changes between 5.0.1 and 5.1 versions, I want to start a new project with 5.1 (because I'm going to havily use javascript), but keep also my older projects running on 5.0.1.

And now what? Do I have to smehow uninstall Rails for rbenv and install it for rvm, or can I just "replace" it??

What about the setting of older projects when switching to rvm? Do the projects need to be updatesd somehow (configuration etc.)?

Thanks


Every Rails project has the version of Rails in the Gemfile that it will use separately from every other app. There's nothing you need to do to manage two different Rails versions.

The only thing you'll want to do is gem install rails to get the latest version and create your new project with rails new myapp. That will make sure the new project starts with Rails 5.1 (or whatever is the latest at the time).

You can also create apps with older versions of rails using rails _4.2.0_ new myapp

Rbenv and Rvm have pretty much nothing to do with this because they are for Ruby versions, not Rails. All of this is taken care of by Bundler.

When you switch apps to work on the correct versions will be automatically used, no changes required by you.


ok, thanks.
But I have Rails 5.0.1 gem already installed. How can I install the newer gem version withou updating the old one?
Can I run multiple gem versions alongside each other?


You just run the commands like I said above. All your gems install side by side so you can always have more than one version installed.


Ok man, cool, thanks!


Here's why that works, as I understand it: Bundler will take care of ensuring that only the gem versions specified in your Gemfile.lock are in Ruby's library load path.


Hey guys,

I ran the following command 
rails _5.1.4_ new mynewapp

in the gemfile it says
gem 'rails', '~> 5.1.4'

however, in the gemfile lock it says
rails (5.1.6)
      actioncable (= 5.1.6)
      actionmailer (= 5.1.6)
      actionpack (= 5.1.6)
      actionview (= 5.1.6)
      activejob (= 5.1.6)
      activemodel (= 5.1.6)
      activerecord (= 5.1.6)
      activesupport (= 5.1.6)
      bundler (>= 1.3.0)
      railties (= 5.1.6)
      sprockets-rails (>= 2.0.0)

It doesn't seem right, is it?

Yep, it's right. The last version number is a patch version for security and bug fixes. You always want the latest version of that.

The first two versions are the ones that change and break things, so those are the ones to worry about being correct.

I see, thank you Chris

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.