How to find where gem files are installed
Use gem environment
to find out about your gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 2.1.5
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin12.4.0]
- INSTALLATION DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /Users/ttm/.rbenv/versions/2.0.0-p247/bin/ruby
- EXECUTABLE DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- SPEC CACHE DIRECTORY: /Users/ttm/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-12
- GEM PATHS:
- /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- /Users/ttm/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- /Users/ttm/.rbenv/libexec
- /Users/ttm/.rbenv/plugins/ruby-build/bin
- /Users/ttm/perl5/perlbrew/bin
- /Users/ttm/perl5/perlbrew/perls/perl-5.18.1/bin
- /Users/ttm/.pyenv/shims
- /Users/ttm/.pyenv/bin
- /Users/ttm/.rbenv/shims
- /Users/ttm/.rbenv/bin
- /Users/ttm/bin
- /usr/local/mysql-5.6.12-osx10.7-x86_64/bin
- /Users/ttm/libsmi/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/bin
Notice the two sections for:
INSTALLATION DIRECTORY
GEM PATHS
Where do gems install?
Look at your gem environment.
In a terminal run gem env
You should see an entry INSTALLATION DIRECTORY
, but there is also GEM PATHS
which is where it's loading all your gems from in your current environment.
List of installed gems?
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.
How can I list content of installed gem?
What you're looking for is:
gem contents gem_name_here
Where are Ruby gems located on a server?
Yep. If you deploy on Heroku, you can see bundler doing its work and pulling down the gems.
How to find the path of where a Ruby Gem is installed
According to this ticket, cucumber >= 2.1.0
is not supported yet. You can downgrade, wait for an update, or use their suggested monkey patch:
find in RubyMine folder file named "formatter_03103.rb" and replace
line 22 todef initialize(step_mother, path_or_io, options)
and line 24 to
tc_initialize(options, '|', path_or_io)
And the command gem environment
returns lots of info about your gems, including the INSTALLATION DIRECTORY
.
How to check if a gem is installed?
General solution
To get the full list of gems that are installed:
gem list
To test for a particular gem, you can use -i
with a regex:
gem list -i "^gem_name$"
(Credit to Timo in the comments for this technique.)
Particular solution for OP
If you can't find data_mapper, it may be that the gem name is different from what you expect.
Also, if you're just doing which brew
to find brew, you aren't finding the gem called brew, you're finding the location of the brew executable. Try gem which brew
instead.
EDIT:
If you're looking for data_mapper by doing which data_mapper
, you probably won't find it. which
is a unix program for finding unix executables, and data_mapper probably doesn't have one.
Since your goal is to verify a gem is installed with the correct version, use gem list
. You can limit to the specific gem by using gem list data_mapper
.
To verify that it's installed and working, you'll have to try to require
the gem and then use it in your code.
How can I see files inside a Ruby .gem?
with gem unpack
You can use the gem unpack
command to extract the contents of a .gem
file into a directory. Assuming you have some_file.gem:
gem unpack some_file.gem
with tar
If you want to list the gem's contents without unpacking it, you can use tar
(a .gem
file is just a .tar
file with a specific format).
tar --to-stdout -xf some_file.gem data.tar.gz | tar -zt
Here's a longer explanation of how this works:
# Download a .gem file
$ gem fetch json_pure -v '2.0.3'
Fetching: json_pure-2.0.3.gem (100%)
Downloaded json_pure-2.0.3
# List the contents of the gem
# You can see that it contains separate files for metadata, the gem files, and a checksum
$ tar -tf json_pure-2.0.3.gem
metadata.gz
data.tar.gz
checksums.yaml.gz
# Extract just the data.tar.gz file, then unzip and list the contents of *that* file.
# --to-stdout so we can pipe it to another command
# -x extract
# -f file
#
# Then:
# -z use gunzip to decompress the .tar.gz file
# -t list the contents of the archive
tar --to-stdout -xf json_pure-2.0.3.gem data.tar.gz | tar -zt
./tests/test_helper.rb
.gitignore
.travis.yml
CHANGES.md
Gemfile
...
In most cases gem unpack
is probably what you want. The main benefit to the tar
command above is that it doesn't create any new directories or actually unpack the files. It might also be useful if you don't have rubygems installed.
Where does bundler store gems?
It depends. In the usual development setup they are installed where they would be when you install a gem "normally" (by running gem install foo
) and bundler won't reinstall gems that are already there. This location depends on how rubygems itself is configured.
If you run bundle install with the --deployment
option then the gems will be installed in a location unique to your app (you can pass this as a separate option but it defaults to vendor/bundle)
You can also run bundle package
to store all the .gem files your app uses in vendor/cache
. Running bundle install
will prefer gems in vendor/cache to gems in other locations.
Related Topics
Rails, How to Render a View/Partial in a Model
Ruby Method Calls Declared in Class Body
Check Whether a String Contains One of Multiple Substrings
How to Change Hash Keys from 'Symbol's to 'String'S
Rails Rbenv: Rails: Command Not Found
Mongo - Ruby Connection Problem
Heroku: Running Imagemagick with Paperclip
How to Pass a Custom Comparator to "Sort"
Ruby SASS, Unable to Resolve Dependancies
God VS. Monit for Process Monitoring
How to Check the Gem Version in Ruby at Runtime
How to Redefine a Ruby Constant Without Warning
How to Change the Position of an Array Element