keruilin
keruilin

Reputation: 17542

Command for displaying a gem's dependencies?

Is there a command that tells you the other gems that a gem depends on?

Also, is there a way to auto install the gem's dependencies?

Upvotes: 29

Views: 22722

Answers (2)

Thomas Langston
Thomas Langston

Reputation: 3735

The following information was pulled from the rubygems command reference linked below.

http://guides.rubygems.org/command-reference/#gem-dependency

The first command you're asking for is "gem dependency". Below is the command description.

gem dependency GEMNAME [options]

Options:
-v, --version VERSION            Specify version of gem to dependency
-r, --[no-]reverse-dependencies  Include reverse dependencies in the output
-p, --pipe                       Pipe Format (name --version ver)

Common Options:
    --source URL                 Use URL as the remote source for gems
-h, --help                       Get help on this command
    --config-file FILE           Use this config file instead of default
    --backtrace                  Show stack backtrace on errors
    --debug                      Turn on Ruby debugging

Arguments:
GEMNAME   name of gems to show

Summary:
Show the dependencies of an installed gem

Defaults:
--version '> 0' --no-reverse

The second command you'll need is "gem install". Dependencies get installed automatically. Read the quote below from the command reference for more detail.

"gem install" will install the named gem. It will attempt a local installation (i.e. a .gem file in the current directory), and if that fails, it will attempt to download and install the most recent version of the gem you want.

If a gem is being installed remotely, and it depends on other gems that are not installed, then gem will download and install those, after you have confirmed the operation.

Upvotes: 39

x-yuri
x-yuri

Reputation: 18973

To find out about a locally installed gem:

$ gem dependency /^rails$/
Gem rails-4.0.12
  actionmailer (= 4.0.12)
  actionpack (= 4.0.12)
  activerecord (= 4.0.12)
  activesupport (= 4.0.12)
  bundler (>= 1.3.0, < 2.0)
  railties (= 4.0.12)
  sprockets-rails (~> 2.0)
...

For an arbitrary gem:

$ gem dependency -rv 4.2.7 /^rails$/
Gem rails-4.2.7
  actionmailer (= 4.2.7)
  actionpack (= 4.2.7)
  actionview (= 4.2.7)
  activejob (= 4.2.7)
  activemodel (= 4.2.7)
  activerecord (= 4.2.7)
  activesupport (= 4.2.7)
  bundler (>= 1.3.0, < 2.0)
  railties (= 4.2.7)
  sprockets-rails (>= 0)

-r stands for --remote, -v for --version. I'm running rubygems-3.0.3. Starting with 3.1.0 you have to omit the regex delimiters:

$ gem dependency -rv 4.2.7 ^rails$
...

Upvotes: 2

Related Questions