This seems like it should be obvious, but I haven't been able to find a way to do it.

My basic problem is this: I've got Ruby 1.8.7 installed on a Scientific Linux 6 system (from the base repository). I'm trying to install some gems via gem install, but I'm running into a lot of gems that require ruby 1.9 or better.

I can specify individual gem versions via the -v parameter, but gem install appears to always pick the highest version available for any gem dependencies, so even if I restrict the version on the gem I want, my installation will still fail because one of the dependencies will require Ruby 1.9. The dependency trees for some of the gems I want are deep and wide; it would take a lot of time to manually figure out which version of each dependency I need and then install each required gem manually before I can work my way up to the one I want. (This is what dependency management is supposed to solve.)

So: is there a way to tell Ruby, "Install gem foo, using only gems that will work with the currently-installed version of Ruby"? (Or even, "Install version x.y.z of gem foo, using only gems that will work with the currently-installed version of Ruby"?)

As I mentioned, I happen to be running Ruby 1.8.7 on Scientific Linux 6, but I doubt any solution is going to be that platform-specific.


Don't use the system ruby for your own programs. Its purpose is to serve system applications which were written in Ruby, and it is only supported by Red Hat for those applications.

Instead, use a Ruby version manager such as rvm or rbenv, with which you can run a current Ruby version and any gems you may need for your own programs.

If you need vendor support, you can also use a Ruby version from Red Hat Software Collections.


Use Bundler

There's no "easy" way to do this, but one pragmatic option is to use Bundler to manage your gems. One comment on Github recommends creating a gem with a strict version requirement on your chosen Ruby, and then letting Bundler handle the remaining dependencies.

I'm not sure that this will work in all cases. Some gems, especially older gems, may not specify the optional required_ruby_version, and may therefore still resolve as installable. However, when you run across such gems, you can manually pin the versions you need in the Gemfile using Bundler's version constraint notation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.