Ruby: How to install a specific version of a ruby gem?
Using the command-line gem
tool, how can I install a specific version of a gem?
Solution 1:
Use the -v
flag:
$ gem install fog -v 1.8
Solution 2:
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).
Solution 3:
For installing
gem install gemname -v versionnumber
For uninstall
gem uninstall gemname -v versionnumber
Solution 4:
for Ruby 1.9+ use colon.
gem install sinatra:1.4.4 prawn:0.13.0