Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out which Ruby version an existing Rails project is based on?

I have an existing Ruby on Rails project. How do I find out which version of Ruby is originally used for the application?

Edit: To sum up this thread: If there are no ruby-version specific gems, every Ruby should work. All your posts were helpful - Thanks.

like image 444
Stephan Avatar asked Jun 07 '11 07:06

Stephan


4 Answers

If no version-specific gems are in use, I'm not sure it's possible to determine the exact ruby version used during development. In any case, the app may work fine against several versions, depending on the features it has.

If the app has comprehensive tests, you could just work back to find the latest version for which all the tests pass.

Checking the minimum version of Ruby compatible with the Rails version used would also help to narrow the field.

like image 196
Mike Woodhouse Avatar answered Nov 05 '22 12:11

Mike Woodhouse


Some people use rvm to manage gemsets in their projects, in this case .rvmrc contains this information, like: "ruby-1.9.2-p180@projectname"

like image 42
Jake Jones Avatar answered Nov 05 '22 10:11

Jake Jones


The answers above are split between two cases:

  1. Where the app is still running (in production or otherwise), where you can connect to production console and check the version
  2. Where the only "artifact" available is the app source code in source control

For #2, the answers above cover it pretty much. You guys are lucky.

For #1, its more of an archealogical expedition. I believe the OP is in that situation and I was in a similar situation today.

Looking at the gem versions is probably the best way to do it.

Here are a few clues that can be used, for everyone's reference. (For the benefit of those who stumble upon this article in the future):

Signs the app was built in Ruby 1.8.7

  • Existence of SystemTimer Gem in the Gemfile.lock (1)
  • Existence of ruby-debug in GemFile, as opposed to ruby-debug19 for 1.9. I believe this could also mean 1.8.6

Signs the app was built in Ruby 1.9

  • Existence of ruby-debug19 in Gemfile
  • String#force_encoding is used
  • encoding: utf-8 at the top of each page

Signs the app was built with jruby

  • Usage of ffi

In General if you read through the old "migration guides from 1.8.7 to 1.9" which lists the differences, you can use those differences to help you find clues. See:

This SO question:

What is the difference between Ruby 1.8 and Ruby 1.9

and this airbnb blog post:

http://nerds.airbnb.com/upgrading-from-ree-187-to-ruby-193/

Good luck!

(1): "Using this gem in Ruby 1.9 is useless and does not make any sense! System Timer is trying to work around some limitation of the "green thread" model used in Ruby 1.8 (MRI). See http://ph7spot.com/musings/system-timer for more details." A drop-in replacement for SystemTimer is timeout.rb from Ruby core.Oct 21, 2011" source: https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=systemtimer%20gem

like image 4
Gal Avatar answered Nov 05 '22 11:11

Gal


For me, I logged into the server where the project was hosted to see what version was installed there: ruby --version

like image 3
Josh M. Avatar answered Nov 05 '22 12:11

Josh M.