Uso del comando gem¶
gem help¶
Ayuda en línea.
$ gem help
RubyGems is a sophisticated package manager for Ruby. This is a
basic help message containing pointers to more information.
Usage:
gem -h/--help
gem -v/--version
gem command [arguments...] [options...]
Examples:
gem install rake
gem list --local
gem build package.gemspec
gem help install
Further help:
gem help commands list all 'gem' commands
gem help examples show some examples of usage
gem help platforms show information about platforms
gem help <COMMAND> show help on COMMAND
(e.g. 'gem help install')
gem server present a web page at
http://localhost:8808/
with info about installed gems
Further information:
http://rubygems.rubyforge.org
$ gem help commands
GEM commands are:
build Build a gem from a gemspec
cert Manage RubyGems certificates and signing settings
check Check installed gems
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
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
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 the named gems (or all installed gems) in the local
repository
which Find the location of a library file you can require
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'.
$ gem help examples
Some examples of 'gem' usage.
* Install 'rake', either from local directory or remote server:
gem install rake
* Install 'rake', only from remote server:
gem install rake --remote
* Install 'rake', but only version 0.3.1, even if dependencies
are not met, and into a user-specific directory:
gem install rake --version 0.3.1 --force --user-install
* List local gems whose name begins with 'D':
gem list D
* List local and remote gems whose name contains 'log':
gem search log --both
* List only remote gems whose name contains 'log':
gem search log --remote
* Uninstall 'rake':
gem uninstall rake
* Create a gem:
See http://rubygems.rubyforge.org/wiki/wiki.pl?CreateAGemInTenMinutes
* See information about RubyGems:
gem environment
* Update all gems on your system:
gem update
gem environment¶
Entorno gem.
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/gomix/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org/", "http://gems.github.com", "https://rubygems.org"]
- REMOTE SOURCES:
- http://rubygems.org/
gem sources¶
Repositorios gems.
Agregando repositorios gem.
$ gem sources -a http://gems.github.com http://gems.github.com added to sources
gem search¶
$ gem search barby --both *** LOCAL GEMS *** barby (0.4.2) *** REMOTE GEMS *** arena_barby (0.3.2) barby (0.5.0) barby-chunky_png (0.3.4)
$ gem search ".ail*" --local *** LOCAL GEMS *** actionmailer (3.2.6, 3.2.5, 2.3.11, 2.3.2) coffee-rails (3.2.2) cucumber-rails (1.3.0) factory_girl_rails (3.3.0) jquery-rails (2.0.2) mail (2.4.4) rails (3.2.6, 2.3.11) railties (3.2.6, 3.2.5) raindrops (0.9.0) rspec-rails (2.10.1) sass-rails (3.2.5)
gem list¶
Listando gems.
Listado de gemas locales cuyos nombres comienzan con D
$ gem list D *** LOCAL GEMS *** daemons (1.1.8) database_cleaner (0.8.0) devise (2.1.0) diff-lcs (1.1.3, 1.1.2) ...
Listado de gemas locales y remotas cuyos nombres contienen 'log'
$ gem list log --both *** LOCAL GEMS *** *** REMOTE GEMS *** log-block (0.3.0) log-me (0.0.3) log2counter (0.0.4) log4j2log4r (0.0.1) log4jruby (0.4.0) ...
Listado de todas las versiones disponibles remotamente
$ gem list log-me --remote --all *** REMOTE GEMS *** log-me (0.0.3, 0.0.2, 0.0.1, 0.0.0)
gem install¶
Instalando gemas.
Instala última versión disponible desde repo local o remoto
$ gem install rake
Instala última versión diponible desde repo remoto
$ gem install --remote rake
Instala última versión a partir de repo remoto y corre los test unit
$ gem install --remote rake --test
Instala versión específica
$ gem install rake --version '0.3.1'
Instala versión de familia de liberación
$ gem install appraisal --version '~>0.4.0'
Instala última versión incluso si no se cumplen las dependencias y se instala en directorio del usuario
$ gem install rake --force --user-install
gem server¶
Muestra una página web en http://localhost:8808/ con la documentación de las gemas instaladas.
$ gem server --verbose Server started at http://0.0.0.0:8808
gem outdated¶
Gemas que necesitan actualización.
$ gem outdated ParseTree (3.0.4 < 3.0.6) RubyInline (3.8.4 < 3.8.6) ZenTest (4.2.1 < 4.4.2) actionmailer (2.3.8 < 3.0.3) actionpack (2.3.8 < 3.0.3) ... stringex (1.1.0 < 1.2.0) test-unit (2.0.9 < 2.1.2) thor (0.13.4 < 0.14.6) vimmate (0.8.1 < 0.9.0)
gem update¶
Actualizando gemas.
Actualiza todas las gemas en el sistema
$ gem update
Actualiza la gema indicada
$ gem update <gem>
gem uninstall¶
Desinstalando gemas.
$ gem uninstall rake
gem which¶
Busca la ubicación de un archivo librería que requiera.
$ gem which sqlite3 /usr/local/share/gems/gems/sqlite3-1.3.6/lib/sqlite3.rb $ gem which sqlite ERROR: Can't find ruby library file or shared library sqlite
gem query¶
Consulta de detalles acerca de una gema.
$ gem query -n unicorn -d
*** LOCAL GEMS ***
unicorn (4.1.1, 4.0.1)
Author: Unicorn hackers
Rubyforge: http://rubyforge.org/projects/mongrel
Homepage: http://unicorn.bogomips.org/
Installed at (4.1.1): /usr/lib/ruby/gems/1.8
(4.0.1): /usr/lib/ruby/gems/1.8
Rack HTTP server for fast clients and Unix
gem contents¶
Listando el contenido de una gema.
$ gem contents unicorn /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/Application_Timeouts /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/CONTRIBUTORS /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/COPYING /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/ChangeLog /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/DESIGN /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/Documentation/GNUmakefile /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/Documentation/unicorn.1.txt /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/Documentation/unicorn_rails.1.txt /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/FAQ /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/GIT-VERSION-FILE /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/GIT-VERSION-GEN /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/GNUmakefile /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/HACKING /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/ISSUES /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/KNOWN_ISSUES /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/LATEST /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/LICENSE /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/Links /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/NEWS /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/PHILOSOPHY ... ... ... /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/test/unit/test_upload.rb /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/test/unit/test_util.rb /usr/lib/ruby/gems/1.8/gems/unicorn-4.1.1/unicorn.gemspec
gem fetch¶
Descarga una gema y la coloca en el directorio actual.
$ gem fetch sqlite3 --verbose GET http://rubygems.org/latest_specs.4.8.gz 302 Moved Temporarily GET http://production.s3.rubygems.org/latest_specs.4.8.gz 304 Not Modified GET http://gems.github.com/latest_specs.4.8.gz 304 Not Modified GET http://rubygems.org/quick/Marshal.4.8/sqlite3-1.3.6.gemspec.rz 302 Moved Temporarily GET http://production.cf.rubygems.org/quick/Marshal.4.8/sqlite3-1.3.6.gemspec.rz 200 OK GET http://rubygems.org/gems/sqlite3-1.3.6.gem 302 Moved Temporarily GET http://production.cf.rubygems.org/gems/sqlite3-1.3.6.gem Fetching: sqlite3-1.3.6.gem (100%) 200 OK Downloaded sqlite3-1.3.6 $ ls -1 sqlite3-1.3.6.gem sqlite3-1.3.6.gem
gem spec¶
O gem specification, este comando gem permite generar el gemspec a partir del paquete gem.
Uso: gem specification [GEMFILE] [FIELD] [options]
De uno de mis paquetes RPM, adaptado para la demostración del uso del comando gem spec.
$ gem spec gem_name.gem -l --ruby > gem_name.gemspec
-l limita la operación al dominio local.
Por omisión el formato de salida es YAML, igualmente puede especificar --yaml .
$ gem spec rhc-0.91.12.gem
--- !ruby/object:Gem::Specification
name: rhc
version: !ruby/object:Gem::Version
version: 0.91.12
segments:
hash:
platform: ruby
authors:
- Red Hat
autorequire:
bindir: bin
cert_chain: []
date: 2012-04-30 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: parseconfig
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
- !ruby/object:Gem::Dependency
name: rest-client
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
description: The client tools for the OpenShift Express platform that allow for application
management.
email: openshift@redhat.com
executables:
- rhc
- rhc-domain
- rhc-app
- rhc-sshkey
- rhc-chk
- rhc-create-app
- rhc-create-domain
- rhc-ctl-domain
- rhc-ctl-app
- rhc-snapshot
- rhc-domain-info
- rhc-user-info
- rhc-tail-files
- rhc-port-forward
extensions:
- ext/mkrf_conf.rb
extra_rdoc_files: []
files:
- lib/rhc-rest.rb
- lib/rhc-rest/version.rb
- lib/rhc-rest/domain.rb
- lib/rhc-rest/cartridge.rb
- lib/rhc-rest/client.rb
- lib/rhc-rest/application.rb
- lib/rhc-rest/exceptions/exceptions.rb
- lib/rhc-rest/user.rb
- lib/rhc-rest/key.rb
- lib/rhc-common.rb
- lib/rhc
- bin/rhc-ctl-app
- bin/rhc-app
- bin/rhc-create-app
- bin/rhc-domain
- bin/rhc-chk
- bin/rhc-create-domain
- bin/rhc-domain-info
- bin/rhc
- bin/rhc-user-info
- bin/rhc-sshkey
- bin/rhc-port-forward
- bin/rhc-snapshot
- bin/rhc-tail-files
- bin/rhc-ctl-domain
- conf/express.conf
- LICENSE
- COPYRIGHT
- README.md
- Rakefile
- ext/mkrf_conf.rb
homepage: https://openshift.redhat.com/app/express
licenses: []
post_install_message: ! " ===================================================\n
\ rhc-rest is no longer needed as an external gem\n - If it is installed,
it will be removed\n - Its libraries are now included in rhc\n -
Any applications requiring rhc-rest will \n still function as expected\n
\ ===================================================\n"
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
hash:
requirements: []
rubyforge_project:
rubygems_version: 1.8.24
signing_key:
specification_version: 3
summary: OpenShift Express Client Tools
test_files: []
El formato Ruby es más compacto, use --ruby.
$ gem spec rhc-0.91.12.gem --ruby
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "rhc"
s.version = "0.91.12"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Red Hat"]
s.date = "2012-04-30"
s.description = "The client tools for the OpenShift Express platform that allow for application management."
s.email = "openshift@redhat.com"
s.executables = ["rhc", "rhc-domain", "rhc-app", "rhc-sshkey", "rhc-chk", "rhc-create-app", "rhc-create-domain", "rhc-ctl-domain", "rhc-ctl-app", "rhc-snapshot", "rhc-domain-info", "rhc-user-info", "rhc-tail-files", "rhc-port-forward"]
s.extensions = ["ext/mkrf_conf.rb"]
s.files = ["lib/rhc-rest.rb", "lib/rhc-rest/version.rb", "lib/rhc-rest/domain.rb", "lib/rhc-rest/cartridge.rb", "lib/rhc-rest/client.rb", "lib/rhc-rest/application.rb", "lib/rhc-rest/exceptions/exceptions.rb", "lib/rhc-rest/user.rb", "lib/rhc-rest/key.rb", "lib/rhc-common.rb", "lib/rhc", "bin/rhc-ctl-app", "bin/rhc-app", "bin/rhc-create-app", "bin/rhc-domain", "bin/rhc-chk", "bin/rhc-create-domain", "bin/rhc-domain-info", "bin/rhc", "bin/rhc-user-info", "bin/rhc-sshkey", "bin/rhc-port-forward", "bin/rhc-snapshot", "bin/rhc-tail-files", "bin/rhc-ctl-domain", "conf/express.conf", "LICENSE", "COPYRIGHT", "README.md", "Rakefile", "ext/mkrf_conf.rb"]
s.homepage = "https://openshift.redhat.com/app/express"
s.post_install_message = " ===================================================\n rhc-rest is no longer needed as an external gem\n - If it is installed, it will be removed\n - Its libraries are now included in rhc\n - Any applications requiring rhc-rest will \n still function as expected\n ===================================================\n"
s.require_paths = ["lib"]
s.rubygems_version = "1.8.24"
s.summary = "OpenShift Express Client Tools"
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<parseconfig>, [">= 0"])
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
s.add_runtime_dependency(%q<rake>, [">= 0"])
else
s.add_dependency(%q<parseconfig>, [">= 0"])
s.add_dependency(%q<rest-client>, [">= 0"])
s.add_dependency(%q<rake>, [">= 0"])
end
else
s.add_dependency(%q<parseconfig>, [">= 0"])
s.add_dependency(%q<rest-client>, [">= 0"])
s.add_dependency(%q<rake>, [">= 0"])
end
end
gem dependency¶
Listado de dependencias de una gema instalada específica.
$ gem dependency actionmailer -v'2.3.11' Gem actionmailer-2.3.11 actionpack (= 2.3.11)
No instalada disponible en repositorios¶
Si no está instalada, pero disponibles en los repositorios, puede simplemente agregar -r.
$ gem dependency rhc -r Gem rhc-1.0.4 activesupport (~> 3.0, development) archive-tar-minitar (>= 0) commander (>= 4.0) cucumber (>= 0, development) dnsruby (>= 0, development) fakefs (>= 0.4, development) highline (>= 1.5.1) net-ssh (>= 2.0.11) open4 (>= 0) rake (>= 0, development) rest-client (>= 1.6) rspec (~> 1.3, development) test-unit (>= 0) thor (>= 0, development) webmock (>= 1.6, development) Gem rhc-rest-0.0.14 rest-client (>= 0) Gem rhcp-0.2.18 json (>= 0.0.0) Gem rhcp_shell-0.2.12 rhcp (>= 0.1.9)
Especificando la versión¶
$ gem dep rhc -r -v 1.2.7 Gem rhc-1.2.7 activesupport (~> 3.0, development) archive-tar-minitar (>= 0) commander (>= 4.0) cucumber (>= 0, development) dnsruby (>= 0, development) fakefs (>= 0.4, development) highline (>= 1.5.1) net-ssh (>= 2.0.11) open4 (>= 0) rake (<= 0.9.2.2, >= 0.8.7, development) rest-client (>= 1.6) rspec (~> 1.3, development) test-unit (>= 0) thor (>= 0, development) webmock (>= 1.6, development)
gem unpack¶
Desempaqueta un gem.
$ gem unpack rhc-0.91.12.gem Unpacked gem: '/home/gomix/tmp/tmp/rhc-0.91.12'] $ ls rhc-0.91.12 bin conf COPYRIGHT ext lib LICENSE Rakefile README.md
gems integradas a Rails¶
Rails soporta cargar gems que se encuentren en vendor/gems antes de cargar los gems disponibles globalmente a nivel de sistema. Después de instalar gems a nivel general, usted puede desempacarlas en vendor/gems, ejemplo:
# cd RAILS_ROOT/vendor # mkdir gems # cd gems # gem unpack cucumber # gem unpack rspec # gem unpack rspec-rails # gem unpack webrat
