How to find where gem files are installed
Asked Answered
A

12

416

I can finds gems that are installed using gem list, but it doesn't show me where the gems are installed.

How can I find where the gems are, and how can I know before installing a gem where it will be installed?

Alaric answered 28/9, 2013 at 21:54 Comment(0)
Z
527

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
Zareba answered 28/9, 2013 at 22:4 Comment(4)
Thanks for your info! In my environment, it seems GEM PATHS are only used first one. Is that right?Alaric
gem env for shortVariolite
I'd look in the EXECUTABLE DIRECTORY.Knopp
The EXECUTABLE DIRECTORY contains the CLI executable versions installed by the gems, but it's not the gems themselves.Zareba
P
229

I found it useful to get a location of the library file with:

gem which *gemname*
Professorship answered 21/7, 2015 at 13:39 Comment(4)
This is a very nice simple method that doesn't require bundler (although I do love bundler :-).Kailyard
simplest answer, doesn't require rails, or bundler! NICE ONE!Norenenorfleet
I like this version because its useful for people doing logstash development (no bundler on my servers). Example is useful: gem which 'logstash/inputs/tcp.rb'Pilate
That will not always work. Works only when your gem exists as executable in your PATH directory.Haycock
C
99

After installing the gems, if you want to know where a particular gem is. Try typing:

 gem list

You will be able to see the list of gems you have installed. Now use bundle show and name the gem you want to know the path for, like this:

 bundle show <gemName>

Or (as of younger versions of bundler):

 bundle info <gemName>
Clonus answered 11/1, 2015 at 13:24 Comment(3)
I'm not sure that this works in all directories. I ran this command and got Could not locate Gemfile or .bundle/ directory.Boner
That's the best way because it shows the full path, (whereas gem env) shows only the parent folder for the gems folder: /home/test/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0. There is a number of folders inside it and your gem may be located in almost any one of them - that's what bundle show <gemName> shows exactly (and gem env) does not.Antitype
[DEPRECATED] use bundle info <gemName> instead of bundle show <gemName>Minnaminnaminnie
S
53

To complete other answers, the gem-path gem can find the installation path of a particular gem.

Installation:

gem install gem-path

Usage:

gem path rails
=> /home/cbliard/.rvm/gems/ruby-2.1.5/gems/rails-4.0.13
gem path rails '< 4'
=> /home/cbliard/.rvm/gems/ruby-2.1.5/gems/rails-3.2.21

This is really handy as you can use it to grep or edit files:

grep -R 'Internal server error' "$(gem path thin)"
subl "$(gem path thin)"
Spiers answered 27/2, 2015 at 9:16 Comment(0)
O
44

You can check it from your command prompt by running gem help commands and then selecting the proper command:

kirti@kirti-Aspire-5733Z:~$  gem help commands
GEM commands are:

    build                  Build a gem from a gemspec
    cert                   Manage RubyGems certificates and signing settings
    check                  Check a gem repository for added or missing files
    cleanup                Clean up old versions of installed gems in the local
                           repository
    contents               Display the contents of the installed gems
    dependency             Show the dependencies of an installed gem
    environment            Display information about the RubyGems environment
    fetch                  Download a gem and place it in the current directory
    generate_index         Generates the index files for a gem server directory
    help                   Provide help on the 'gem' command
    install                Install a gem into the local repository
    list                   Display gems whose name starts with STRING
    lock                   Generate a lockdown list of gems
    mirror                 Mirror all gem files (requires rubygems-mirror)
    outdated               Display all gems that need updates
    owner                  Manage gem owners on RubyGems.org.
    pristine               Restores installed gems to pristine condition from
                           files located in the gem cache
    push                   Push a gem up to RubyGems.org
    query                  Query gem information in local or remote repositories
    rdoc                   Generates RDoc for pre-installed gems
    regenerate_binstubs    Re run generation of executable wrappers for gems.
    search                 Display all gems whose name contains STRING
    server                 Documentation and gem repository HTTP server
    sources                Manage the sources and cache file RubyGems uses to
                           search for gems
    specification          Display gem specification (in yaml)
    stale                  List gems along with access times
    uninstall              Uninstall gems from the local repository
    unpack                 Unpack an installed gem to the current directory
    update                 Update installed gems to the latest version
    which                  Find the location of a library file you can require
    yank                   Remove a specific gem version release from
                           RubyGems.org

For help on a particular command, use 'gem help COMMAND'.

Commands may be abbreviated, so long as they are unambiguous.
e.g. 'gem i rake' is short for 'gem install rake'.
kirti@kirti-Aspire-5733Z:~$ 

Now from the above I can see the command environment is helpful. So I would do:

kirti@kirti-Aspire-5733Z:~$ gem help environment
Usage: gem environment [arg] [options]


  Common Options:
    -h, --help                       Get help on this command
    -V, --[no-]verbose               Set the verbose level of output
    -q, --quiet                      Silence commands
        --config-file FILE           Use this config file instead of default
        --backtrace                  Show stack backtrace on errors
        --debug                      Turn on Ruby debugging


  Arguments:
    packageversion  display the package version
    gemdir          display the path where gems are installed
    gempath         display path used to search for gems
    version         display the gem format version
    remotesources   display the remote gem servers
    platform        display the supported gem platforms
    <omitted>       display everything

  Summary:
    Display information about the RubyGems environment

  Description:
    The RubyGems environment can be controlled through command line arguments,
    gemrc files, environment variables and built-in defaults.

    Command line argument defaults and some RubyGems defaults can be set in a
    ~/.gemrc file for individual users and a /etc/gemrc for all users. These
    files are YAML files with the following YAML keys:

      :sources: A YAML array of remote gem repositories to install gems from
      :verbose: Verbosity of the gem command. false, true, and :really are the
                levels
      :update_sources: Enable/disable automatic updating of repository metadata
      :backtrace: Print backtrace when RubyGems encounters an error
      :gempath: The paths in which to look for gems
      :disable_default_gem_server: Force specification of gem server host on
    push
      <gem_command>: A string containing arguments for the specified gem command

    Example:

      :verbose: false
      install: --no-wrappers
      update: --no-wrappers
      :disable_default_gem_server: true

    RubyGems' default local repository can be overridden with the GEM_PATH and
    GEM_HOME environment variables. GEM_HOME sets the default repository to
    install into. GEM_PATH allows multiple local repositories to be searched for
    gems.

    If you are behind a proxy server, RubyGems uses the HTTP_PROXY,
    HTTP_PROXY_USER and HTTP_PROXY_PASS environment variables to discover the
    proxy server.

    If you would like to push gems to a private gem server the RUBYGEMS_HOST
    environment variable can be set to the URI for that server.

    If you are packaging RubyGems all of RubyGems' defaults are in
    lib/rubygems/defaults.rb.  You may override these in
    lib/rubygems/defaults/operating_system.rb
kirti@kirti-Aspire-5733Z:~$ 

Finally to show you what you asked, I would do:

kirti@kirti-Aspire-5733Z:~$ gem environment gemdir
/home/kirti/.rvm/gems/ruby-2.0.0-p0
kirti@kirti-Aspire-5733Z:~$ gem environment gempath
/home/kirti/.rvm/gems/ruby-2.0.0-p0:/home/kirti/.rvm/gems/ruby-2.0.0-p0@global
kirti@kirti-Aspire-5733Z:~$ 
Ornie answered 28/9, 2013 at 21:57 Comment(1)
Thanks! I didn't know the gem help commands. And I should've write that I'm using rbenv.Alaric
T
25

You can trick gem open into displaying the gem path:

VISUAL=echo gem open gem-name

Example:

VISUAL=echo gem open rails
=> /usr/local/opt/asdf/installs/ruby/2.4.3/lib/ruby/gems/2.4.0/gems/rails-5.1.4

It just works, and no third party gem is necessary.

Titty answered 25/2, 2018 at 20:32 Comment(2)
This is perfect! It's a shame that this useful information is a side effect instead of an intentional command. Note that you can also specify the "editor" with the -e option (-e echo), if it's easier than setting an environment variable.Handling
Beautiful! Just omit the last part and go into that directory in your editor and tear apart the gems ;-)Rainfall
C
17

gem env works just like gem environment. Saves some typing.

# gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.0.0
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/2.0.0
     - /root/.gem/ruby/2.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
Coseismal answered 23/4, 2014 at 4:50 Comment(1)
It's not "works just like", it is the same command. gem help commands returns "Commands may be abbreviated, so long as they are unambiguous. e.g. 'gem i rake' is short for 'gem install rake'." In other words, gem environment, gem env and gem e all work but gem environment is self-documenting for those who don't know what it's doing so we should use that for first-timers.Zareba
E
6

The gem env lists where gems can be installed, but this can be 10 or more locations. If you want to know where a particular gem is installed, you can execute:

gem list -d <gemname>

Example output:

tilt (2.0.9)
    Author: Ryan Tomayko
    Homepage: http://github.com/rtomayko/tilt/
    License: MIT
    Installed at: /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0

    Generic interface to multiple Ruby template engines
Escapism answered 24/9, 2019 at 20:40 Comment(0)
O
3

if you are using rvm tool you can run this command to print gem path:

rvm gemdir

OR

echo $GEM_HOME
Olympiaolympiad answered 15/1, 2020 at 22:2 Comment(0)
D
3

This works and gives you the installed at path for each gem. This super helpful when trying to do multi-stage docker builds.. You can copy in the specific directory post-bundle install.

bash-4.4# gem list -d

Output::

aasm (5.0.6)
    Authors: Thorsten Boettger, Anil Maurya
    Homepage: https://github.com/aasm/aasm
    License: MIT
    Installed at: /usr/local/bundle

  State machine mixin for Ruby objects
Daveen answered 14/5, 2020 at 14:36 Comment(0)
L
0

One can go to rails console and do

Gem.bin_path('<gem-name>', '<gem-executable-name>')

It returns exact path to the gem file executable.

Ref: https://www.rubydoc.info/github/rubygems/rubygems/Gem.bin_path

Lobster answered 28/10, 2022 at 8:18 Comment(0)
A
0
gem info YourTargetName

for example :

gem info cocoapods-packager


*** LOCAL GEMS ***

cocoapods-packager (1.5.0)
    Authors: Kyle Fuller, Boris Bügling
    Homepage: https://github.com/CocoaPods/cocoapods-packager
    License: MIT
    Installed at: /Users/localName/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0

CocoaPods plugin which allows you to generate a framework or static
library from a podspec.
Aponte answered 1/4, 2023 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.