Using the command-line gem
tool, how can I install a specific version of a gem?
8 Answers
Use the -v
flag:
$ gem install fog -v 1.8
-
74If, like me, you have previously installed a later version of your gem, then you must uninstall the later version with e.g.
gem uninstall fog
. It will ask you which version to uninstall if you have more than one.– DizzleyCommented Jan 26, 2014 at 18:18 -
4i have 3 versions of rake:
gem list | grep rake
=rake (10.1.1, 10.1.0, 0.8.7)
.. i got a rails 2.3.5 project and another that's 3.0 that i'm working on at the same time.. how do i use a specific version of rake for each project (ie on command line?)– abboodCommented Mar 13, 2014 at 8:40 -
@abbood
rake _10.1.1_ ...
should work, for whoever wants to know :)– Koen.Commented Jan 29, 2017 at 10:00 -
1Worth noting that this does not seem to affect executable binaries. Uninstalling the previous version worked for binaries though. Commented Feb 21, 2019 at 8:16
-
2I probably search and find this once a year lol, that's how often I use it but great! Commented Feb 23, 2021 at 20:14
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).
-
This worked for ~>, but what if you have '< 0.9, >= 0.7' type of situation? I tried applying two v arguments and it appears as though the first was ignored. Using the a comma separator wouldn't even parse. I ended up removing the greater than requirement and it happened to install an acceptable version, but having a formal solution would be nice. Commented Jul 14, 2015 at 0:25
-
-
It means that the last digit is allowed to grow (stackoverflow.com/questions/5170547/…)– schmijosCommented Aug 16, 2017 at 8:35
-
1Mael Stor's answer tells us that Joseph Coco's suggested two v arguments from six years earlier now works. Commented Apr 24, 2021 at 17:31
for Ruby 1.9+ use colon.
gem install sinatra:1.4.4 prawn:0.13.0
-
-
please tell me the output of
gem sources
, if it's empty, add a repo using this command:gem sources -a https://rubygems.org/
– KokizzuCommented May 30, 2014 at 1:28 -
my
gem -v
shows1.8.23
versus your2.2.2
. Looks like this feature is new :)– kolyptoCommented May 30, 2014 at 18:21 -
1Ruby 1.8 is already end of support ruby-lang.org/en/news/2013/06/30/we-retire-1-8-7– KokizzuCommented Jun 11, 2014 at 2:26
For installing
gem install gemname -v versionnumber
For uninstall
gem uninstall gemname -v versionnumber
As others have noted, in general use the -v
flag for the gem install
command.
If you're developing a gem locally, after cutting a gem from your gemspec:
$ gem install gemname-version.gem
Assuming version 0.8, it would look like this:
$ gem install gemname-0.8.gem
-
3Great answer. I suggest you add another code block for the flag "-v" option though. As my eyes read the answer they immediately went to the code blocks and not the text surrounding it. If others do the same they'll miss the "-v" portion.– CamHartCommented Jun 22, 2016 at 18:57
You can use the -v
or --version
flag. For example
gem install bitclock -v '< 0.0.2'
To specify upper AND lower version boundaries you can specify the --version
flag twice
gem install bitclock -v '>= 0.0.1' -v '< 0.0.2'
or use the syntax (for example)
gem install bitclock -v '>= 0.0.1, < 0.0.2'
The other way to do it is
gem install bitclock:'>= 0.0.1'
but with the last option it is not possible to specify upper and lower bounderies simultaneously.
[gem 3.0.3 and ruby 2.6.6]
-
How to make gem to not upgrade dependencies,
gem install "asciidoctor:2.0.10" "asciidoctor-diagram:2.0.5"
, always upgrade asciidoctor to a later version than 2.0.10, I've tried to use the options--minimal-deps
and--conservative
? I've worked around this withgem install --no-document --ignore-dependencies "asciidoctor-diagram:2.0.5"
butasciidoctor-diagram
only has a single dep, how to handle that more elegantly.– bric3Commented Nov 6, 2020 at 13:48 -
@Brice I couldn't reproduce this behaviour with the command line
gem install 'asciidoctor:2.0.10' 'asciidoctor-diagram:2.0.5'
. It installs exactly these versions. Which gem version is reported when you typegem --version
? Commented Nov 9, 2020 at 11:29 -
It happens with
gem
3.1.4, in theregistry.fedoraproject.org/fedora-minimal
image. Using this command for exampledocker run -it --rm registry.fedoraproject.org/fedora-minimal bash -c "microdnf install -y ruby; gem install 'asciidoctor:2.0.10' 'asciidoctor-diagram:2.0.5'"
, I see that first asciidoctor 2.0.10 is installed, then asciidoctor 2.0.12.– bric3Commented Nov 10, 2020 at 14:40
Linux
To install different version of ruby, check the latest version of package using apt
as below:
$ apt-cache madison ruby
ruby | 1:1.9.3 | http://ftp.uk.debian.org/debian/ wheezy/main amd64 Packages
ruby | 4.5 | http://ftp.uk.debian.org/debian/ squeeze/main amd64 Packages
Then install it:
$ sudo apt-get install ruby=1:1.9.3
To check what's the current version, run:
$ gem --version # Check for the current user.
$ sudo gem --version # Check globally.
If the version is still old, you may try to switch the version to new by using ruby version manager (rvm
) by:
rvm 1.9.3
Note: You may prefix it by sudo
if rvm
was installed globally. Or run /usr/local/rvm/scripts/rvm
if your command rvm
is not in your global PATH
. If rvm installation process failed, see the troubleshooting section.
Troubleshooting:
If you still have the old version, you may try to install rvm (ruby version manager) via:
sudo apt-get install curl # Install curl first curl -sSL https://get.rvm.io | bash -s stable --ruby # Install only for the user. #or:# curl -sSL https://get.rvm.io | sudo bash -s stable --ruby # Install globally.
then if installed locally (only for current user), load rvm via:
source /usr/local/rvm/scripts/rvm; rvm 1.9.3
if globally (for all users), then:
sudo bash -c "source /usr/local/rvm/scripts/rvm; rvm 1.9.3"
if you still having problem with the new ruby version, try to install it by rvm via:
source /usr/local/rvm/scripts/rvm && rvm install ruby-1.9.3 # Locally. sudo bash -c "source /usr/local/rvm/scripts/rvm && rvm install ruby-1.9.3" # Globally.
if you'd like to install some gems globally and you have rvm already installed, you may try:
rvmsudo gem install [gemname]
instead of:
gem install [gemname] # or: sudo gem install [gemname]
Note: It's prefered to NOT use sudo to work with RVM gems. When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening.
Prior to installing, you can check the available versions with the list command.
gem list ^[gemname]$ --remote --all
gem install [gemname] -v [version]