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

  • SEARCH
  • Home
  • 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 261729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:27:23+00:00 2026-05-11T22:27:23+00:00

Is there a way to check if some gem is currently installed, via the

  • 0

Is there a way to check if some gem is currently installed, via the Gem module? From ruby code, not by executing ‘gem list’…

To clarify – I don’t want to load the library. I just want to check if it’s available, so all the rescue LoadError solutions don’t help me. Also I don’t care if the gem itself will work or not, only whether it’s installed.

  • 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-11T22:27:23+00:00Added an answer on May 11, 2026 at 10:27 pm

    IMHO the best way is to try to load/require the GEM and rescue the Exception, as Ray has already shown. It’s safe to rescue the LoadError exception because it’s not raised by the GEM itself but it’s the standard behavior of the require command.

    You can also use the gem command instead.

    begin
      gem "somegem"
      # with requirements
      gem "somegem", ">=2.0"
    rescue Gem::LoadError
      # not installed
    end
    

    The gem command has the same behavior of the require command, with some slight differences. AFAIK, it still tries to autoload the main GEM file.

    Digging into the rubygems.rb file (line 310) I found the following execution

    matches = Gem.source_index.find_name(gem.name, gem.version_requirements)
    report_activate_error(gem) if matches.empty?
    

    It can provide you some hints about how to make a dirty check without actually loading the library.

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

Sidebar

Related Questions

is there some pretty way to check if some specific user (not the one
I need to check in some fast way if there is any text nodes
Is there a way to check if the user gave permission or not to
Is there some way to check the status of a curl command? Say, I
Is there any way to check if an included document via include('to_include.php') has returned
I know that there are some restricted api's or code that are not allowed
Is there any way to check whether some string compatible with some MS SQL
Possible Duplicate: Check if JavaScript is enabled with PHP Is there some way to
In objective-c, is there some way to check a variable hasn't been released by
Is there any way to check or verify a source code file in R

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.