How to List All Versions of a Gem Available at a Remote Site

How do I list all versions of a gem available at a remote site?

Well, it was easier than I thought (well, not really, let's say as easy as it should be):

gem list rhc --remote --all

Which returns:

*** REMOTE GEMS ***
rhc (0.84.15, 0.84.13, 0.83.9, 0.82.18, 0.81.14, 0.80.5, 0.79.5, 0.77.8, 0.75.9, 0.74.6, 0.74.5, 0.73.14, 0.72.29, 0.71.2, 0.69.6, 0.69.3, 0.68.5)
rhcp (0.2.18, 0.2.17, 0.2.16, 0.2.15, 0.2.14, 0.1.9, 0.1.8, 0.1.7, 0.1.6, 0.1.5, 0.1.4, 0.1.3, 0.1.2)
rhcp_shell (0.2.12, 0.2.11, 0.0.9, 0.0.7, 0.0.6, 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1)

How do I find the lastest version of a gem?

gem list rails -ra means:

"show me all the rails versions available for installation"


Usage: gem list [STRING] [options]
[...]
-a, --all Display all gem versions
-r, --remote Restrict operations to the REMOTE domain

The resulting response can be quite long for gems that have had a number of revisions.

How to get all Gems names via web?

You could use https://rubygems.org/latest_specs.4.8.gz which returns gzipped marshal dumped array like this:

[["abscss", Gem::Version.new("0.0.1"), "ruby"],
["absee", Gem::Version.new("1.0"), "ruby"],
["absentee_camper", Gem::Version.new("0.0.7"), "ruby"],
["absgit", Gem::Version.new("0.3.0"), "ruby"],
["absinthe", Gem::Version.new("0.0.3"), "ruby"],
["absolute", Gem::Version.new("0.0.5"), "ruby"],
["AbsoluteRenamer", Gem::Version.new("1.1.2"), "ruby"],
["AbsoluteRenamer-date", Gem::Version.new("0.1.0"), "ruby"]]

But if you're in Ruby, I strongly recommend using the gem fetcher:

require 'rubygems/spec_fetcher'
fetcher = Gem::SpecFetcher.fetcher
tuples = fetcher.detect(:released) { true }

tuples is now an array of tuples of [Gem::NameTuple, Gem::Remote]. Some examples of what you can do with this:

tuples[1337][0].name # => GraphvizR
tuples[1337][0].version.to_s # => "0.1.0"

using bundler to load different versions of gems for different platforms

You can do it like that:

# Windows
gem "eventmachine", "~> 1.0.0.beta.4.1", :platform => [:mswin, :mingw]

# C Ruby (MRI) or Rubinius, but NOT Windows
gem "eventmachine", :platform => :ruby

Full list of available platforms:

ruby      C Ruby (MRI) or Rubinius, but NOT Windows
ruby_18 ruby AND version 1.8
ruby_19 ruby AND version 1.9
ruby_20 ruby AND version 2.0
mri Same as ruby, but not Rubinius
mri_18 mri AND version 1.8
mri_19 mri AND version 1.9
mri_20 mri AND version 2.0
rbx Same as ruby, but only Rubinius (not MRI)
jruby JRuby
mswin Windows
mingw Windows 'mingw32' platform (aka RubyInstaller)
mingw_18 mingw AND version 1.8
mingw_19 mingw AND version 1.9
mingw_20 mingw AND version 2.0

You can find more information in Gemfile(5) man page here (see 'Platforms' section).

Another approach is to use RUBY_PLATFORM constant:

if RUBY_PLATFORM =~ /win32/
gem "eventmachine", "~> 1.0.0.beta.4.1"
else
gem "eventmachine"
end

I haven't seen full list of available values for RUBY_PLATFORM but you can run

ruby -e 'puts RUBY_PLATFORM'

on both your platforms and see the difference.

Getting all URLs using anemone gem (very large site)

If anyone out there needs <= 100,000 URLs, the Ruby Gem Spidr is a great way to go.

How to search for gems inside of Ruby code, or where did Gem::RemoteInstaller go?

Gem::RemoteInstaller has been removed from the rubygems since version 1.0. This was a while ago. If you are looking for the ability to set someone up with gems that they may not have, I would strongly suggest bundler (actually I think all ruby projects should use it) http://gembundler.com

OK, you can try:

 require 'rubygems'
r = Gem::SpecFetcher.new
r.suggest_gems_from_name('rails')
=> ["rails"]

How to find where gem files are installed

Use gem environment to find out about your gem environment:

RubyGems Environment:
- RUBYGEMS VERSION: 2.1.5
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin12.4.0]
- INSTALLATION DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /Users/ttm/.rbenv/versions/2.0.0-p247/bin/ruby
- EXECUTABLE DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- SPEC CACHE DIRECTORY: /Users/ttm/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-12
- GEM PATHS:
- /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- /Users/ttm/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- /Users/ttm/.rbenv/libexec
- /Users/ttm/.rbenv/plugins/ruby-build/bin
- /Users/ttm/perl5/perlbrew/bin
- /Users/ttm/perl5/perlbrew/perls/perl-5.18.1/bin
- /Users/ttm/.pyenv/shims
- /Users/ttm/.pyenv/bin
- /Users/ttm/.rbenv/shims
- /Users/ttm/.rbenv/bin
- /Users/ttm/bin
- /usr/local/mysql-5.6.12-osx10.7-x86_64/bin
- /Users/ttm/libsmi/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/bin

Notice the two sections for:

  • INSTALLATION DIRECTORY
  • GEM PATHS

Getting all URLs using anemone gem (very large site)

If anyone out there needs <= 100,000 URLs, the Ruby Gem Spidr is a great way to go.

Ruby command line gem search returns no results

The command gem search defaults to searching remotely only from version 1.8.25 onward. To search remote gems with older versions you have to use the -r (or --remote) option:

$ gem --version
1.8.23
$ gem search ^rails
*** LOCAL GEMS ***
...
$ gem search -r ^rails
** REMOTE GEMS ***
...

See gem help search and the Rubygems changelog for more informations.



Related Topics



Leave a reply



Submit