Is there an easy way to install Ruby gems for the currently-installed Ruby version?

asciiphil asked:

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.

My answer:


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.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.