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 6 Comments
gem uninstall fog. It will ask you which version to uninstall if you have more than one.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?)rake _10.1.1_ ... should work, for whoever wants to know :)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).
4 Comments
~> stand for?for Ruby 1.9+ use colon.
gem install sinatra:1.4.4 prawn:0.13.0 4 Comments
gem sources, if it's empty, add a repo using this command: gem sources -a https://rubygems.org/gem -v shows 1.8.23 versus your 2.2.2. Looks like this feature is new :)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 1 Comment
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]
3 Comments
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 with gem install --no-document --ignore-dependencies "asciidoctor-diagram:2.0.5" but asciidoctor-diagram only has a single dep, how to handle that more elegantly.gem install 'asciidoctor:2.0.10' 'asciidoctor-diagram:2.0.5'. It installs exactly these versions. Which gem version is reported when you type gem --version?gem 3.1.4, in the registry.fedoraproject.org/fedora-minimal image. Using this command for example docker 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.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.3if 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.