web-dev-qa-db-fra.com

Comment trouver où les fichiers gem sont installés

Je peux trouver des gems installés à l'aide de gem list, mais cela ne m'indique pas où les gems sont installés.

Comment puis-je localiser les gemmes et comment puis-je savoir avant d'installer un gem là où il sera installé?

241
ironsand

Utilisez gem environment pour en savoir plus sur votre environnement bijou:

_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
_

Notez les deux sections pour:

  • _INSTALLATION DIRECTORY_
  • _GEM PATHS_
323
the Tin Man

J'ai trouvé utile d'obtenir un emplacement du fichier de bibliothèque avec:

gem which *gemname*
127
Rustam A. Gasanov

Après avoir installé les gemmes, si vous voulez savoir où se trouve un gemme particulier. Essayez de taper:

 gem list

Vous pourrez voir la liste des gemmes que vous avez installées. Maintenant, utilisez bundle show et nommez la gemme pour laquelle vous voulez connaître le chemin, comme ceci:

 bundle show <gemName>
65
ishanbakshi

Pour compléter d'autres réponses, le gem-path gem peut trouver le chemin d'installation d'un gem particulier.

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

C'est vraiment pratique car vous pouvez l'utiliser pour grep ou éditer des fichiers:

grep -R 'Internal server error' "$(gem path thin)"
subl "$(gem path thin)"
46
cbliard

Vous pouvez le vérifier depuis l'invite de commande en exécutant gem help commands puis en sélectionnant la commande appropriée:

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:~$ 

À partir de ce qui précède, je peux voir que la commande environment est utile. Alors je ferais:

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:~$ 

Enfin pour vous montrer ce que vous avez demandé, je ferais:

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:~$ 
29
Arup Rakshit

gem env fonctionne exactement comme gem environment. Enregistre un peu de frappe.

# 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/
13
slayedbylucifer

Vous pouvez tromper gem open en affichant le chemin d'accès à la gemme:

VISUAL=echo gem open gem-name

Exemple:

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
9
Jerome Dalbert

J'imagine que rvm (et rbenv) enregistre le chemin d'accès à Gem Home dans une variable d'environnement. Si je cours

env | grep GEM_

Je reçois

  • GEM_HOME=/Users/Me/.rvm/gems/Ruby-2.2.3@my_project
  • GEM_PATH=/Users/Me/.rvm/gems/Ruby-2.2.3@my_project: /Users/Me/.rvm/gems/Ruby-2.2.3@my_project

Je pense que $ GEM_HOME est le lieu qui vous intéresse

Les gems seront installés dans $ GEM_HOME "/ gems"

0
Hirurg103