List of installed gems?












118















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?










share|improve this question





























    118















    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?










    share|improve this question



























      118












      118








      118


      34






      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?










      share|improve this question
















      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?







      ruby rubygems






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 20 '16 at 1:06









      Eric Leschinski

      89k40327281




      89k40327281










      asked Mar 3 '11 at 6:56









      Prakash RamanPrakash Raman

      4,7532259105




      4,7532259105
























          11 Answers
          11






          active

          oldest

          votes


















          49














          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.






          share|improve this answer





















          • 2





            Should be noted, "Dependency.new w/ a regexp is deprecated" now.

            – Martin Poljak
            Dec 11 '13 at 9:31





















          289














          This lists all the gems I have installed.



          gem query --local


          http://guides.rubygems.org/command-reference/#gem-list



          See 2.7 Listing all installed gems






          share|improve this answer





















          • 4





            The OP wanted a Ruby method to do it, not a command-line.

            – the Tin Man
            Dec 11 '13 at 12:15






          • 34





            When I look at the upvotes, then this answer is what most people wanted. :)

            – kaiser
            Sep 8 '14 at 10:22






          • 1





            there is a better answer in the question itself gem list.

            – blueray
            Jul 11 '18 at 14:31



















          24














          Both



          gem query --local


          and



           ruby -S gem list --local


          list 69 entries



          While



          ruby -e 'puts Gem::Specification.all_names'


          gives me 82



          I used wc -l to get the numbers. Not sure if that is the right way to check. Tried to redirect the output to text files and diff'ed but that didn't help - will need to compare manually one by one.






          share|improve this answer





















          • 1





            The reason is simple. The first command only adds 1 entry per gem and lists the versions in brackets on the same line. The last ruby command lists each gem version on a separate line. For e.g.: sass (3.3.14, 3.3.7, 3.3.6, 3.2.19) vs. sass-3.3.14, sass-3.3.7, sass-3.3.6, sass-3.2.19

            – kaiser
            Sep 8 '14 at 10:30





















          9














          There's been a method for this for ages:



          ruby -e 'puts Gem::Specification.all_names'





          share|improve this answer
























          • ruby -e 'puts Gem::Specification.all_names' gives me "-e:1: uninitialized constant Gem (NameError)" How do I solve this?

            – Metahuman
            Oct 5 '16 at 21:18



















          4














          Gem::Specification.map {|a| a.name}


          However, if your app uses Bundler it will return only list of dependent local gems. To get all installed:



          def all_installed_gems
          Gem::Specification.all = nil
          all = Gem::Specification.map{|a| a.name}
          Gem::Specification.reset
          all
          end





          share|improve this answer
























          • This gives NoMethodError: undefined method any?' for nil:NilClass` when I use it (in a rails console).

            – iconoclast
            Feb 9 at 0:38



















          3














          A more modern version would be to use something akin to the following...



          require 'rubygems'
          puts Gem::Specification.all().map{|g| [g.name, g.version.to_s].join('-') }


          NOTE: very similar the first part of an answer by Evgeny... but due to page formatting, it's easy to miss.






          share|improve this answer































            3














            by one command:



            Gem::Specification.all_names





            share|improve this answer
























            • can you improve your answer?

              – MZaragoza
              Dec 22 '17 at 17:00



















            2














            Try it in the terminal:



            ruby -S gem list --local





            share|improve this answer



















            • 1





              Notice that the OP wanted a Ruby method.

              – the Tin Man
              Dec 11 '13 at 12:15






            • 1





              good on Kurt for not resting on his laurels, though...

              – dax
              Nov 6 '14 at 10:31



















            2














            Here's a really nice one-liner to print all the Gems along with their version, homepage, and description:



            Gem::Specification.sort{|a,b| a.name <=> b.name}.map {|a| puts "#{a.name} (#{a.version})"; puts "-" * 50; puts a.homepage; puts a.description; puts "nn"};nil





            share|improve this answer

































              1














              Maybe you can get the files (gems) from the gems directory?



              gemsdir = "gems directory"
              gems = Dir.new(gemsdir).entries





              share|improve this answer































                1














                From within your debugger type $LOAD_PATH to get a list of your gems. If you don't have a debugger, install pry:



                gem install pry
                pry
                Pry(main)> $LOAD_PATH


                This will output an array of your installed gems.






                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5177634%2flist-of-installed-gems%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  11 Answers
                  11






                  active

                  oldest

                  votes








                  11 Answers
                  11






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  49














                  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.






                  share|improve this answer





















                  • 2





                    Should be noted, "Dependency.new w/ a regexp is deprecated" now.

                    – Martin Poljak
                    Dec 11 '13 at 9:31


















                  49














                  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.






                  share|improve this answer





















                  • 2





                    Should be noted, "Dependency.new w/ a regexp is deprecated" now.

                    – Martin Poljak
                    Dec 11 '13 at 9:31
















                  49












                  49








                  49







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 11 '13 at 12:54

























                  answered Mar 3 '11 at 7:22









                  the Tin Manthe Tin Man

                  136k27173256




                  136k27173256








                  • 2





                    Should be noted, "Dependency.new w/ a regexp is deprecated" now.

                    – Martin Poljak
                    Dec 11 '13 at 9:31
















                  • 2





                    Should be noted, "Dependency.new w/ a regexp is deprecated" now.

                    – Martin Poljak
                    Dec 11 '13 at 9:31










                  2




                  2





                  Should be noted, "Dependency.new w/ a regexp is deprecated" now.

                  – Martin Poljak
                  Dec 11 '13 at 9:31







                  Should be noted, "Dependency.new w/ a regexp is deprecated" now.

                  – Martin Poljak
                  Dec 11 '13 at 9:31















                  289














                  This lists all the gems I have installed.



                  gem query --local


                  http://guides.rubygems.org/command-reference/#gem-list



                  See 2.7 Listing all installed gems






                  share|improve this answer





















                  • 4





                    The OP wanted a Ruby method to do it, not a command-line.

                    – the Tin Man
                    Dec 11 '13 at 12:15






                  • 34





                    When I look at the upvotes, then this answer is what most people wanted. :)

                    – kaiser
                    Sep 8 '14 at 10:22






                  • 1





                    there is a better answer in the question itself gem list.

                    – blueray
                    Jul 11 '18 at 14:31
















                  289














                  This lists all the gems I have installed.



                  gem query --local


                  http://guides.rubygems.org/command-reference/#gem-list



                  See 2.7 Listing all installed gems






                  share|improve this answer





















                  • 4





                    The OP wanted a Ruby method to do it, not a command-line.

                    – the Tin Man
                    Dec 11 '13 at 12:15






                  • 34





                    When I look at the upvotes, then this answer is what most people wanted. :)

                    – kaiser
                    Sep 8 '14 at 10:22






                  • 1





                    there is a better answer in the question itself gem list.

                    – blueray
                    Jul 11 '18 at 14:31














                  289












                  289








                  289







                  This lists all the gems I have installed.



                  gem query --local


                  http://guides.rubygems.org/command-reference/#gem-list



                  See 2.7 Listing all installed gems






                  share|improve this answer















                  This lists all the gems I have installed.



                  gem query --local


                  http://guides.rubygems.org/command-reference/#gem-list



                  See 2.7 Listing all installed gems







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 26 '17 at 13:46









                  Bhargav Rao

                  30.7k2092113




                  30.7k2092113










                  answered Mar 9 '13 at 15:08









                  frankstunerfrankstuner

                  3,03321214




                  3,03321214








                  • 4





                    The OP wanted a Ruby method to do it, not a command-line.

                    – the Tin Man
                    Dec 11 '13 at 12:15






                  • 34





                    When I look at the upvotes, then this answer is what most people wanted. :)

                    – kaiser
                    Sep 8 '14 at 10:22






                  • 1





                    there is a better answer in the question itself gem list.

                    – blueray
                    Jul 11 '18 at 14:31














                  • 4





                    The OP wanted a Ruby method to do it, not a command-line.

                    – the Tin Man
                    Dec 11 '13 at 12:15






                  • 34





                    When I look at the upvotes, then this answer is what most people wanted. :)

                    – kaiser
                    Sep 8 '14 at 10:22






                  • 1





                    there is a better answer in the question itself gem list.

                    – blueray
                    Jul 11 '18 at 14:31








                  4




                  4





                  The OP wanted a Ruby method to do it, not a command-line.

                  – the Tin Man
                  Dec 11 '13 at 12:15





                  The OP wanted a Ruby method to do it, not a command-line.

                  – the Tin Man
                  Dec 11 '13 at 12:15




                  34




                  34





                  When I look at the upvotes, then this answer is what most people wanted. :)

                  – kaiser
                  Sep 8 '14 at 10:22





                  When I look at the upvotes, then this answer is what most people wanted. :)

                  – kaiser
                  Sep 8 '14 at 10:22




                  1




                  1





                  there is a better answer in the question itself gem list.

                  – blueray
                  Jul 11 '18 at 14:31





                  there is a better answer in the question itself gem list.

                  – blueray
                  Jul 11 '18 at 14:31











                  24














                  Both



                  gem query --local


                  and



                   ruby -S gem list --local


                  list 69 entries



                  While



                  ruby -e 'puts Gem::Specification.all_names'


                  gives me 82



                  I used wc -l to get the numbers. Not sure if that is the right way to check. Tried to redirect the output to text files and diff'ed but that didn't help - will need to compare manually one by one.






                  share|improve this answer





















                  • 1





                    The reason is simple. The first command only adds 1 entry per gem and lists the versions in brackets on the same line. The last ruby command lists each gem version on a separate line. For e.g.: sass (3.3.14, 3.3.7, 3.3.6, 3.2.19) vs. sass-3.3.14, sass-3.3.7, sass-3.3.6, sass-3.2.19

                    – kaiser
                    Sep 8 '14 at 10:30


















                  24














                  Both



                  gem query --local


                  and



                   ruby -S gem list --local


                  list 69 entries



                  While



                  ruby -e 'puts Gem::Specification.all_names'


                  gives me 82



                  I used wc -l to get the numbers. Not sure if that is the right way to check. Tried to redirect the output to text files and diff'ed but that didn't help - will need to compare manually one by one.






                  share|improve this answer





















                  • 1





                    The reason is simple. The first command only adds 1 entry per gem and lists the versions in brackets on the same line. The last ruby command lists each gem version on a separate line. For e.g.: sass (3.3.14, 3.3.7, 3.3.6, 3.2.19) vs. sass-3.3.14, sass-3.3.7, sass-3.3.6, sass-3.2.19

                    – kaiser
                    Sep 8 '14 at 10:30
















                  24












                  24








                  24







                  Both



                  gem query --local


                  and



                   ruby -S gem list --local


                  list 69 entries



                  While



                  ruby -e 'puts Gem::Specification.all_names'


                  gives me 82



                  I used wc -l to get the numbers. Not sure if that is the right way to check. Tried to redirect the output to text files and diff'ed but that didn't help - will need to compare manually one by one.






                  share|improve this answer















                  Both



                  gem query --local


                  and



                   ruby -S gem list --local


                  list 69 entries



                  While



                  ruby -e 'puts Gem::Specification.all_names'


                  gives me 82



                  I used wc -l to get the numbers. Not sure if that is the right way to check. Tried to redirect the output to text files and diff'ed but that didn't help - will need to compare manually one by one.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 12 '14 at 15:13









                  tripleee

                  94.1k13132186




                  94.1k13132186










                  answered Mar 12 '14 at 13:33









                  RoobieRoobie

                  681718




                  681718








                  • 1





                    The reason is simple. The first command only adds 1 entry per gem and lists the versions in brackets on the same line. The last ruby command lists each gem version on a separate line. For e.g.: sass (3.3.14, 3.3.7, 3.3.6, 3.2.19) vs. sass-3.3.14, sass-3.3.7, sass-3.3.6, sass-3.2.19

                    – kaiser
                    Sep 8 '14 at 10:30
















                  • 1





                    The reason is simple. The first command only adds 1 entry per gem and lists the versions in brackets on the same line. The last ruby command lists each gem version on a separate line. For e.g.: sass (3.3.14, 3.3.7, 3.3.6, 3.2.19) vs. sass-3.3.14, sass-3.3.7, sass-3.3.6, sass-3.2.19

                    – kaiser
                    Sep 8 '14 at 10:30










                  1




                  1





                  The reason is simple. The first command only adds 1 entry per gem and lists the versions in brackets on the same line. The last ruby command lists each gem version on a separate line. For e.g.: sass (3.3.14, 3.3.7, 3.3.6, 3.2.19) vs. sass-3.3.14, sass-3.3.7, sass-3.3.6, sass-3.2.19

                  – kaiser
                  Sep 8 '14 at 10:30







                  The reason is simple. The first command only adds 1 entry per gem and lists the versions in brackets on the same line. The last ruby command lists each gem version on a separate line. For e.g.: sass (3.3.14, 3.3.7, 3.3.6, 3.2.19) vs. sass-3.3.14, sass-3.3.7, sass-3.3.6, sass-3.2.19

                  – kaiser
                  Sep 8 '14 at 10:30













                  9














                  There's been a method for this for ages:



                  ruby -e 'puts Gem::Specification.all_names'





                  share|improve this answer
























                  • ruby -e 'puts Gem::Specification.all_names' gives me "-e:1: uninitialized constant Gem (NameError)" How do I solve this?

                    – Metahuman
                    Oct 5 '16 at 21:18
















                  9














                  There's been a method for this for ages:



                  ruby -e 'puts Gem::Specification.all_names'





                  share|improve this answer
























                  • ruby -e 'puts Gem::Specification.all_names' gives me "-e:1: uninitialized constant Gem (NameError)" How do I solve this?

                    – Metahuman
                    Oct 5 '16 at 21:18














                  9












                  9








                  9







                  There's been a method for this for ages:



                  ruby -e 'puts Gem::Specification.all_names'





                  share|improve this answer













                  There's been a method for this for ages:



                  ruby -e 'puts Gem::Specification.all_names'






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 25 '14 at 14:57









                  BarryBarry

                  3,5932839




                  3,5932839













                  • ruby -e 'puts Gem::Specification.all_names' gives me "-e:1: uninitialized constant Gem (NameError)" How do I solve this?

                    – Metahuman
                    Oct 5 '16 at 21:18



















                  • ruby -e 'puts Gem::Specification.all_names' gives me "-e:1: uninitialized constant Gem (NameError)" How do I solve this?

                    – Metahuman
                    Oct 5 '16 at 21:18

















                  ruby -e 'puts Gem::Specification.all_names' gives me "-e:1: uninitialized constant Gem (NameError)" How do I solve this?

                  – Metahuman
                  Oct 5 '16 at 21:18





                  ruby -e 'puts Gem::Specification.all_names' gives me "-e:1: uninitialized constant Gem (NameError)" How do I solve this?

                  – Metahuman
                  Oct 5 '16 at 21:18











                  4














                  Gem::Specification.map {|a| a.name}


                  However, if your app uses Bundler it will return only list of dependent local gems. To get all installed:



                  def all_installed_gems
                  Gem::Specification.all = nil
                  all = Gem::Specification.map{|a| a.name}
                  Gem::Specification.reset
                  all
                  end





                  share|improve this answer
























                  • This gives NoMethodError: undefined method any?' for nil:NilClass` when I use it (in a rails console).

                    – iconoclast
                    Feb 9 at 0:38
















                  4














                  Gem::Specification.map {|a| a.name}


                  However, if your app uses Bundler it will return only list of dependent local gems. To get all installed:



                  def all_installed_gems
                  Gem::Specification.all = nil
                  all = Gem::Specification.map{|a| a.name}
                  Gem::Specification.reset
                  all
                  end





                  share|improve this answer
























                  • This gives NoMethodError: undefined method any?' for nil:NilClass` when I use it (in a rails console).

                    – iconoclast
                    Feb 9 at 0:38














                  4












                  4








                  4







                  Gem::Specification.map {|a| a.name}


                  However, if your app uses Bundler it will return only list of dependent local gems. To get all installed:



                  def all_installed_gems
                  Gem::Specification.all = nil
                  all = Gem::Specification.map{|a| a.name}
                  Gem::Specification.reset
                  all
                  end





                  share|improve this answer













                  Gem::Specification.map {|a| a.name}


                  However, if your app uses Bundler it will return only list of dependent local gems. To get all installed:



                  def all_installed_gems
                  Gem::Specification.all = nil
                  all = Gem::Specification.map{|a| a.name}
                  Gem::Specification.reset
                  all
                  end






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 24 '12 at 8:15









                  EvgeniiEvgenii

                  21.5k20110141




                  21.5k20110141













                  • This gives NoMethodError: undefined method any?' for nil:NilClass` when I use it (in a rails console).

                    – iconoclast
                    Feb 9 at 0:38



















                  • This gives NoMethodError: undefined method any?' for nil:NilClass` when I use it (in a rails console).

                    – iconoclast
                    Feb 9 at 0:38

















                  This gives NoMethodError: undefined method any?' for nil:NilClass` when I use it (in a rails console).

                  – iconoclast
                  Feb 9 at 0:38





                  This gives NoMethodError: undefined method any?' for nil:NilClass` when I use it (in a rails console).

                  – iconoclast
                  Feb 9 at 0:38











                  3














                  A more modern version would be to use something akin to the following...



                  require 'rubygems'
                  puts Gem::Specification.all().map{|g| [g.name, g.version.to_s].join('-') }


                  NOTE: very similar the first part of an answer by Evgeny... but due to page formatting, it's easy to miss.






                  share|improve this answer




























                    3














                    A more modern version would be to use something akin to the following...



                    require 'rubygems'
                    puts Gem::Specification.all().map{|g| [g.name, g.version.to_s].join('-') }


                    NOTE: very similar the first part of an answer by Evgeny... but due to page formatting, it's easy to miss.






                    share|improve this answer


























                      3












                      3








                      3







                      A more modern version would be to use something akin to the following...



                      require 'rubygems'
                      puts Gem::Specification.all().map{|g| [g.name, g.version.to_s].join('-') }


                      NOTE: very similar the first part of an answer by Evgeny... but due to page formatting, it's easy to miss.






                      share|improve this answer













                      A more modern version would be to use something akin to the following...



                      require 'rubygems'
                      puts Gem::Specification.all().map{|g| [g.name, g.version.to_s].join('-') }


                      NOTE: very similar the first part of an answer by Evgeny... but due to page formatting, it's easy to miss.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 21 '13 at 15:15









                      paul.beltpaul.belt

                      24933




                      24933























                          3














                          by one command:



                          Gem::Specification.all_names





                          share|improve this answer
























                          • can you improve your answer?

                            – MZaragoza
                            Dec 22 '17 at 17:00
















                          3














                          by one command:



                          Gem::Specification.all_names





                          share|improve this answer
























                          • can you improve your answer?

                            – MZaragoza
                            Dec 22 '17 at 17:00














                          3












                          3








                          3







                          by one command:



                          Gem::Specification.all_names





                          share|improve this answer













                          by one command:



                          Gem::Specification.all_names






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 22 '17 at 16:27









                          Игорь ХлебниковИгорь Хлебников

                          512




                          512













                          • can you improve your answer?

                            – MZaragoza
                            Dec 22 '17 at 17:00



















                          • can you improve your answer?

                            – MZaragoza
                            Dec 22 '17 at 17:00

















                          can you improve your answer?

                          – MZaragoza
                          Dec 22 '17 at 17:00





                          can you improve your answer?

                          – MZaragoza
                          Dec 22 '17 at 17:00











                          2














                          Try it in the terminal:



                          ruby -S gem list --local





                          share|improve this answer



















                          • 1





                            Notice that the OP wanted a Ruby method.

                            – the Tin Man
                            Dec 11 '13 at 12:15






                          • 1





                            good on Kurt for not resting on his laurels, though...

                            – dax
                            Nov 6 '14 at 10:31
















                          2














                          Try it in the terminal:



                          ruby -S gem list --local





                          share|improve this answer



















                          • 1





                            Notice that the OP wanted a Ruby method.

                            – the Tin Man
                            Dec 11 '13 at 12:15






                          • 1





                            good on Kurt for not resting on his laurels, though...

                            – dax
                            Nov 6 '14 at 10:31














                          2












                          2








                          2







                          Try it in the terminal:



                          ruby -S gem list --local





                          share|improve this answer













                          Try it in the terminal:



                          ruby -S gem list --local






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 6 '13 at 8:51









                          Kurt RussellKurt Russell

                          1241214




                          1241214








                          • 1





                            Notice that the OP wanted a Ruby method.

                            – the Tin Man
                            Dec 11 '13 at 12:15






                          • 1





                            good on Kurt for not resting on his laurels, though...

                            – dax
                            Nov 6 '14 at 10:31














                          • 1





                            Notice that the OP wanted a Ruby method.

                            – the Tin Man
                            Dec 11 '13 at 12:15






                          • 1





                            good on Kurt for not resting on his laurels, though...

                            – dax
                            Nov 6 '14 at 10:31








                          1




                          1





                          Notice that the OP wanted a Ruby method.

                          – the Tin Man
                          Dec 11 '13 at 12:15





                          Notice that the OP wanted a Ruby method.

                          – the Tin Man
                          Dec 11 '13 at 12:15




                          1




                          1





                          good on Kurt for not resting on his laurels, though...

                          – dax
                          Nov 6 '14 at 10:31





                          good on Kurt for not resting on his laurels, though...

                          – dax
                          Nov 6 '14 at 10:31











                          2














                          Here's a really nice one-liner to print all the Gems along with their version, homepage, and description:



                          Gem::Specification.sort{|a,b| a.name <=> b.name}.map {|a| puts "#{a.name} (#{a.version})"; puts "-" * 50; puts a.homepage; puts a.description; puts "nn"};nil





                          share|improve this answer






























                            2














                            Here's a really nice one-liner to print all the Gems along with their version, homepage, and description:



                            Gem::Specification.sort{|a,b| a.name <=> b.name}.map {|a| puts "#{a.name} (#{a.version})"; puts "-" * 50; puts a.homepage; puts a.description; puts "nn"};nil





                            share|improve this answer




























                              2












                              2








                              2







                              Here's a really nice one-liner to print all the Gems along with their version, homepage, and description:



                              Gem::Specification.sort{|a,b| a.name <=> b.name}.map {|a| puts "#{a.name} (#{a.version})"; puts "-" * 50; puts a.homepage; puts a.description; puts "nn"};nil





                              share|improve this answer















                              Here's a really nice one-liner to print all the Gems along with their version, homepage, and description:



                              Gem::Specification.sort{|a,b| a.name <=> b.name}.map {|a| puts "#{a.name} (#{a.version})"; puts "-" * 50; puts a.homepage; puts a.description; puts "nn"};nil






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jan 1 at 22:25









                              Iulian Onofrei

                              4,10934279




                              4,10934279










                              answered Jul 7 '17 at 21:01









                              Darren HicksDarren Hicks

                              3,9162430




                              3,9162430























                                  1














                                  Maybe you can get the files (gems) from the gems directory?



                                  gemsdir = "gems directory"
                                  gems = Dir.new(gemsdir).entries





                                  share|improve this answer




























                                    1














                                    Maybe you can get the files (gems) from the gems directory?



                                    gemsdir = "gems directory"
                                    gems = Dir.new(gemsdir).entries





                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      Maybe you can get the files (gems) from the gems directory?



                                      gemsdir = "gems directory"
                                      gems = Dir.new(gemsdir).entries





                                      share|improve this answer













                                      Maybe you can get the files (gems) from the gems directory?



                                      gemsdir = "gems directory"
                                      gems = Dir.new(gemsdir).entries






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 3 '11 at 7:05









                                      FossmoFossmo

                                      1,8262042




                                      1,8262042























                                          1














                                          From within your debugger type $LOAD_PATH to get a list of your gems. If you don't have a debugger, install pry:



                                          gem install pry
                                          pry
                                          Pry(main)> $LOAD_PATH


                                          This will output an array of your installed gems.






                                          share|improve this answer




























                                            1














                                            From within your debugger type $LOAD_PATH to get a list of your gems. If you don't have a debugger, install pry:



                                            gem install pry
                                            pry
                                            Pry(main)> $LOAD_PATH


                                            This will output an array of your installed gems.






                                            share|improve this answer


























                                              1












                                              1








                                              1







                                              From within your debugger type $LOAD_PATH to get a list of your gems. If you don't have a debugger, install pry:



                                              gem install pry
                                              pry
                                              Pry(main)> $LOAD_PATH


                                              This will output an array of your installed gems.






                                              share|improve this answer













                                              From within your debugger type $LOAD_PATH to get a list of your gems. If you don't have a debugger, install pry:



                                              gem install pry
                                              pry
                                              Pry(main)> $LOAD_PATH


                                              This will output an array of your installed gems.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jan 9 '16 at 20:57









                                              Nicolai RoblesNicolai Robles

                                              874




                                              874






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5177634%2flist-of-installed-gems%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  MongoDB - Not Authorized To Execute Command

                                                  Npm cannot find a required file even through it is in the searched directory

                                                  in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith