1

I have several versions of a Ruby gem installed on my machine. I'm using one version for development, but the other is used for production and deployment, so I need them both. Is there a simple way to specify which version of the gem should be used?

Since they are the same gem, their binary names conflict, and I have to physically remove one or the other from the gems directory and leave the other one that I want to keep active. But I'd like to be able to jump back and forth between development and production gems, and I am hoping there is a better way.

Edit: I guess I should have make it more clear. When I said development, I meant development of the gem, not the "Rails development environment." So what I'm doing is I forked a gem from Github, and I am using both my fork and the original gem from the commandline. Not as part of Rails.

1 Answer 1

4

See the Rubygems manual. Pretty sure this is still valid in Rails 3.

For example:

require 'rubygems' gem 'activerecord', '= 1.4.0' 

Other valid operators (in lieu of =) are >, >=, <, <=; I believe they also take the ~ modifier.

Update (2014-03-09): The original Rubygems manual page no longer exists due to a redesign; please refer to the Bundler documentation instead, under the GEMS > VERSION section.

Sign up to request clarification or add additional context in comments.

5 Comments

No no, I don't want to use it as part of Rails. I need to use the gems from the commandline.
The answer is still valid. See docs.rubygems.org/read/chapter/4#page71 for the authoritative answer in the RubyGems manual.
Yes - I meant that ~ would be used as a modifier, eg ~> (as you said). Sorry, I should've been clearer. Thanks!
This link no longer goes to a particular part of the manual. If someone knows where it was meant to go, could they possibly copy the useful part of the manual into the answer as well as re-linking?
@Matt Updated the answer - please refer to bundler.io/man/gemfile.5.html, under GEMS > VERSION.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.