Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: How to install a specific version of a ruby gem?

Tags:

ruby

rubygems

Using the command-line gem tool, how can I install a specific version of a gem?

like image 709
mjs Avatar asked Jun 10 '13 14:06

mjs


People also ask

How do I specify a gem version?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .

How do I run a specific version of Ruby?

Selecting a version of Ruby You'll need to install bundler 1.2. x or above to use the ruby keyword and bundler 1.13. x or above to use a Ruby version specifier. You can use the ruby keyword in your app's Gemfile to specify a specific version of Ruby.


2 Answers

Use the --version parameter (shortcut -v):

$ gem install rails -v 0.14.1 … Successfully installed rails-0.14.1 

You can also use version comparators like >= or ~>

$ gem install rails -v '~> 0.14.0' … Successfully installed rails-0.14.4 

With newer versions of rubygems you can tighten up your requirements:

$ gem install rails -v '~> 0.14.0, < 0.14.4' … Successfully installed rails-0.14.3 

Since some time now you can also specify versions of multiple gems:

$ gem install rails:0.14.4 rubyzip:'< 1' … Successfully installed rails-0.14.4 Successfully installed rubyzip-0.9.9 

But this doesn't work for more than one comparator per gem (yet).

like image 35
schmijos Avatar answered Oct 07 '22 19:10

schmijos


Use the -v flag:

$ gem install fog -v 1.8 
like image 107
mjs Avatar answered Oct 07 '22 17:10

mjs