List of installed gems?
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
add a comment |
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
add a comment |
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
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
ruby rubygems
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
add a comment |
add a comment |
11 Answers
11
active
oldest
votes
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.
2
Should be noted, "Dependency.new w/ a regexp is deprecated" now.
– Martin Poljak
Dec 11 '13 at 9:31
add a comment |
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
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 itselfgem list
.
– blueray
Jul 11 '18 at 14:31
add a comment |
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.
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 lastruby
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
add a comment |
There's been a method for this for ages:
ruby -e 'puts Gem::Specification.all_names'
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
add a comment |
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
This givesNoMethodError: undefined method
any?' for nil:NilClass` when I use it (in arails console
).
– iconoclast
Feb 9 at 0:38
add a comment |
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.
add a comment |
by one command:
Gem::Specification.all_names
can you improve your answer?
– MZaragoza
Dec 22 '17 at 17:00
add a comment |
Try it in the terminal:
ruby -S gem list --local
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
add a comment |
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
add a comment |
Maybe you can get the files (gems) from the gems directory?
gemsdir = "gems directory"
gems = Dir.new(gemsdir).entries
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
2
Should be noted, "Dependency.new w/ a regexp is deprecated" now.
– Martin Poljak
Dec 11 '13 at 9:31
add a comment |
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.
2
Should be noted, "Dependency.new w/ a regexp is deprecated" now.
– Martin Poljak
Dec 11 '13 at 9:31
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
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 itselfgem list
.
– blueray
Jul 11 '18 at 14:31
add a comment |
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
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 itselfgem list
.
– blueray
Jul 11 '18 at 14:31
add a comment |
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
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
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 itselfgem list
.
– blueray
Jul 11 '18 at 14:31
add a comment |
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 itselfgem 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
add a comment |
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.
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 lastruby
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
add a comment |
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.
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 lastruby
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
add a comment |
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.
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.
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 lastruby
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
add a comment |
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 lastruby
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
add a comment |
There's been a method for this for ages:
ruby -e 'puts Gem::Specification.all_names'
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
add a comment |
There's been a method for this for ages:
ruby -e 'puts Gem::Specification.all_names'
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
add a comment |
There's been a method for this for ages:
ruby -e 'puts Gem::Specification.all_names'
There's been a method for this for ages:
ruby -e 'puts Gem::Specification.all_names'
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
add a comment |
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
add a comment |
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
This givesNoMethodError: undefined method
any?' for nil:NilClass` when I use it (in arails console
).
– iconoclast
Feb 9 at 0:38
add a comment |
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
This givesNoMethodError: undefined method
any?' for nil:NilClass` when I use it (in arails console
).
– iconoclast
Feb 9 at 0:38
add a comment |
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
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
answered Jan 24 '12 at 8:15
EvgeniiEvgenii
21.5k20110141
21.5k20110141
This givesNoMethodError: undefined method
any?' for nil:NilClass` when I use it (in arails console
).
– iconoclast
Feb 9 at 0:38
add a comment |
This givesNoMethodError: undefined method
any?' for nil:NilClass` when I use it (in arails 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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered May 21 '13 at 15:15
paul.beltpaul.belt
24933
24933
add a comment |
add a comment |
by one command:
Gem::Specification.all_names
can you improve your answer?
– MZaragoza
Dec 22 '17 at 17:00
add a comment |
by one command:
Gem::Specification.all_names
can you improve your answer?
– MZaragoza
Dec 22 '17 at 17:00
add a comment |
by one command:
Gem::Specification.all_names
by one command:
Gem::Specification.all_names
answered Dec 22 '17 at 16:27


Игорь ХлебниковИгорь Хлебников
512
512
can you improve your answer?
– MZaragoza
Dec 22 '17 at 17:00
add a comment |
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
add a comment |
Try it in the terminal:
ruby -S gem list --local
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
add a comment |
Try it in the terminal:
ruby -S gem list --local
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
add a comment |
Try it in the terminal:
ruby -S gem list --local
Try it in the terminal:
ruby -S gem list --local
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
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
add a comment |
add a comment |
Maybe you can get the files (gems) from the gems directory?
gemsdir = "gems directory"
gems = Dir.new(gemsdir).entries
add a comment |
Maybe you can get the files (gems) from the gems directory?
gemsdir = "gems directory"
gems = Dir.new(gemsdir).entries
add a comment |
Maybe you can get the files (gems) from the gems directory?
gemsdir = "gems directory"
gems = Dir.new(gemsdir).entries
Maybe you can get the files (gems) from the gems directory?
gemsdir = "gems directory"
gems = Dir.new(gemsdir).entries
answered Mar 3 '11 at 7:05
FossmoFossmo
1,8262042
1,8262042
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 9 '16 at 20:57
Nicolai RoblesNicolai Robles
874
874
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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