Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021126
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:18:47+00:00 2026-05-20T10:18:47+00:00

Is there a Ruby method I can call to get the list of installed

  • 0

Is there a Ruby method I can call to get the list of installed gems?

I want to parse the output of gem list.

Is there a different way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:18:48+00:00Added an answer on May 20, 2026 at 10:18 am

    The Gem command is included with Ruby 1.9+ now, and is a standard addition to Ruby pre-1.9.

    require 'rubygems'
    
    name = /^/i
    dep = Gem::Dependency.new(name, Gem::Requirement.default)
    specs = Gem.source_index.search(dep)
    puts specs[0..5].map{ |s| "#{s.name} #{s.version}" }
    # >> Platform 0.4.0
    # >> abstract 1.0.0
    # >> actionmailer 3.0.5
    # >> actionpack 3.0.5
    # >> activemodel 3.0.5
    # >> activerecord 3.0.5
    

    Here’s an updated way to get a list:

    require 'rubygems'
    
    def local_gems
       Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
    end
    

    Because local_gems relies on group_by, it returns a hash of the gems, where the key is the gem’s name, and the value is an array of the gem specifications. The value is an array of the instances of that gem that is installed, sorted by the version number.

    That makes it possible to do things like:

    my_local_gems = local_gems()
    
    my_local_gems['actionmailer']
    # => [Gem::Specification.new do |s|
    #       s.authors = ["David Heinemeier Hansson"]
    #       s.date = Time.utc(2013, 12, 3)
    #       s.dependencies = [Gem::Dependency.new("actionpack",
    #         Gem::Requirement.new(["= 4.0.2"]),
    #         :runtime),
    #        Gem::Dependency.new("mail",
    #         Gem::Requirement.new(["~> 2.5.4"]),
    #         :runtime)]
    #       s.description = "Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments."
    #       s.email = "david@loudthinking.com"
    #       s.homepage = "http://www.rubyonrails.org"
    #       s.licenses = ["MIT"]
    #       s.name = "actionmailer"
    #       s.require_paths = ["lib"]
    #       s.required_ruby_version = Gem::Requirement.new([">= 1.9.3"])
    #       s.requirements = ["none"]
    #       s.rubygems_version = "2.0.14"
    #       s.specification_version = 4
    #       s.summary = "Email composition, delivery, and receiving framework (part of Rails)."
    #       s.version = Gem::Version.new("4.0.2")
    #       end]
    

    And:

    puts my_local_gems.map{ |name, specs| 
      [ 
        name,
        specs.map{ |spec| spec.version.to_s }.join(',')
      ].join(' ') 
    }
    # >> actionmailer 4.0.2
    ...
    # >> arel 4.0.1,5.0.0
    ...
    # >> ZenTest 4.9.5
    # >> zucker 13.1
    

    The last example is similar to the gem query --local command-line, only you have access to all the information for a particular gem’s specification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Ruby, is there the equivalent of the __str__() method that you can define
I want to add a foo method to Ruby's Kernel module, so I can
Is there a good ruby gem for a WYSIWYG editor that will easily work
Is there any way a database change (say an insert statement) can trigger a
Not sure on my Ruby syntax here. I want to define a method that
Is there a Ruby equivalent for Python's is? It tests whether two objects are
Is there in Ruby some functionality/syntax to compare two floats with delta? Something similar
Is there any Ruby equivalent for Python's builtin zip function? If not, what is
So in Ruby there is a trick to specify infinity: 1.0/0 => Infinity I
Whats the best/easiest GUI library out there for Ruby? I would prefer a cross-platform

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.