28

Say I have two versions of a gem installed (somegem versions 0.10.6 and 0.10.5) and I want to run the earlier version from the commandline. Do I have to uninstall the newer version? Is there a way I can use a flag to specify which version I want to use? Something like...

somegem /path/to/dir --version 0.10.5

I checked the rubygems documentation, and it only describes how to use a specific version when you require a gem from a file, but nothing about how to do it from the commandline.

picardo
  • 24,530
  • 33
  • 104
  • 151
  • Why would you "load a gem" from the command line? Surely there's no point unless you're using the gem inside Ruby code (and then, you follow the instructions for requiring it from a file...) – Gareth Oct 31 '10 at 02:52
  • I'm not trying to load, but simply run the binaries of a gem. Surely they are not the same thing. I need to have the run the older versions at times, or I'd like to run a gem I have modified, but also run the original gem when necessary. Since they are both named "somegem" Ruby can't tell the difference and uses the latest version's binary. – picardo Oct 31 '10 at 04:50

1 Answers1

53
somegem _0.10.5_ /path/to/dir

No link to documentation, because apparently there isn't any.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • Do you reckon it's because the Rubygems folk are lax with documentation, or that this functionality is somewhat unsupported, or a mixture of the two? – Andrew Grimm Oct 31 '10 at 23:12
  • 3
    This (actually, `ruby -S somegem _1.4.3_`, because `somegem` defaulted to running ruby1.9.1) worked for me with rubygems 1.8.15. – Andrew Grimm Oct 15 '12 at 03:27
  • Apparently it is done in the install script, where the command being executed is actually wrapped to add this behavior https://github.com/rubygems/rubygems/blob/abf89e04954b8a2ddfb6948d0860111990a6efa2/lib/rubygems/installer.rb#L652 but I also could not find it documented anywhere – Felipe Sabino Oct 02 '14 at 14:55
  • Actually, there is definite mention of this in the command reference. https://guides.rubygems.org/command-reference/#gem-install _For gems with executables ruby installs a wrapper file into the executable directory by default. This can be overridden with the –no-wrappers option. The wrapper allows you to choose among alternate gem versions using version._ _For example rake _0.7.3_ --version will run rake version 0.7.3 if a newer version is also installed._ – Satyajeet Kanetkar Dec 10 '20 at 15:13