Ask A Question

Notifications

You’re not receiving notifications from this thread.

Multiple Rubies using Rbenv

shakycode asked in Ruby

I'm having total brainfog right now with rbenv, so please excuse the newbie question.

I have rbenv installed and my global ruby install is 1.9.3-p194 which I've developed multiple apps in. I'm working on new apps and would like to use 2.2.0 alongside Rails 4.2.0. I want to keep my legacy apps working in development using 1.9.3 but also work on the newer apps using different Ruby versions.

Wouldn't it be something like this?
rbenv install 2.2.0
cd ~/code/mynewapp
rbenv local 2.2.0

This should generate a .ruby-version file which tells rbenv what version to use right? Then from there I can bundle my new app and build the gems/etc?

Would it make more sense to install Ruby 2.2.0 then set it rbenv global 2.2.0 then in each Rails project I'm working on do rbenv local 1.9.3-p194 for each project that I'm using so it doesn't break things?

I'm just concerned about wiping out my dev environment and having to start from scratch which would waste time.

Reply

I simply set the Ruby version manually per project.

cd my-rails-app
echo "2.2.1" > .ruby-version
git add .ruby-version

When you cd into the directory, it should autodetect and switch for you.

You probably would want to do the same thing in your 1.9.3 apps to set their versions. If you do that, then your global ruby version doesn't matter since each app specifies what they need.

With that approach, you won't have to worry about wiping out any of your existing rubies or gems. rbenv will just seamlessly switch between whatever is already installed.

Reply

Sweet, thanks for the answer Chris. I was overcomplicating it I think. I went into a newer repo that needs Ruby 2.2.0 and just did

cd newrepo
rbenv install 2.2.0
rbenv local 2.2.0

And it did the same thing as echoing the version in your example. But your way seems way simpler. :) I'm going to do this for all 5 of my existing apps and set their versions (which is unfortunately all 1.9.3-p194). Then I'll do the same for the new apps I build.

I noticed when I cloned a new Rails 4.2 app repo and tried to do bundle install to install dependencies it said bundle command not found, exists only in these versions 1.9.3. So I ran gem install bunlder to get it to compile against 2.2.0

I think I'm in a better place now. Thanks for your help as always. I'm sure I'll be posting more often.

Reply

Yeah since bundler is a gem, you have to install it separately for each version of Ruby. Maybe they'll have it ship with Ruby at some point.

That definitely seems like the simplest approach that I've found over the years. I still haven't played with chruby, but it seems all the ruby version managers treat .ruby-version pretty consistently now so it shouldn't really matter what you use which is great!

Reply

Right you are sir. Actually there's been talk of shipping bundler with Ruby, although I forget where I saw it. That would be nice though. Having the .ruby-version in your repo also helps when you are switching Ruby in both dev and prod. Although I don't think I'll tackle upgrading Ruby in production this week. :)

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.