A RubyGems plugin that shows which installed gems depend on a specific gem. Similar to yarn why or npm why.
# Install the plugin
gem install gem-why
# Find all dependency chains to rake (default - shows transitive dependencies)
gem why rake
# Show only direct dependencies
gem why rake --direct
# Visualize dependencies as a tree
gem why rake --treeUnlike most dependency tools that show only direct dependencies by default, gem why defaults to deep dependency analysis because:
- Most real-world scenarios involve transitive dependencies - you typically want to know "why is this gem even installed?" not just "what directly depends on it?"
- Debugging is easier when you see the full chain immediately - you can trace exactly how a problematic gem entered your dependency tree
- Mirrors
yarn whybehavior - the inspiration for this tool also defaults to showing full dependency chains - Direct lookups are still fast - use
--directwhen you specifically need just immediate dependents
Install the gem by executing:
gem install gem-whyThe plugin will automatically be available as a gem command after installation.
| Mode | Command | Shows | Best For |
|---|---|---|---|
| Deep (default) | gem why GEMNAME |
Full dependency chains with paths | Understanding transitive dependencies |
| Direct | gem why GEMNAME --direct |
Only direct dependencies | Quick lookup of immediate dependents |
| Tree | gem why GEMNAME --tree |
Visual tree structure | Complex dependency visualization |
To see which gems depend on a specific gem:
gem why GEMNAME [options]Bonus: If you add this gem to your project, you can use the bundle exec gem why command to understand the dependencies of your gems in your project.
Show all dependency chains leading to a gem (including transitive dependencies):
$ gem why concurrent-ruby
Dependency chains leading to concurrent-ruby:
rails => activesupport => concurrent-ruby
└─ rails (8.0.3) requires activesupport = 8.0.3
└─ activesupport (8.0.3) requires concurrent-ruby ~> 1.0, >= 1.3.1
actionpack => activesupport => concurrent-ruby
└─ actionpack (8.0.3) requires activesupport = 8.0.3
└─ activesupport (8.0.3) requires concurrent-ruby ~> 1.0, >= 1.3.1
Total: 10 root gem(s) depend on concurrent-ruby
Found 25 dependency chain(s)
Tip: Use --direct for direct dependencies only or --tree for a visual treeCheck which gems directly depend on rake:
$ gem why rake --direct
Gems that depend on rake:
ast (2.4.3) requires rake ~> 13.2
minitest (5.16.0) requires rake >= 0
rubocop (1.21.0) requires rake >= 0
...
Total: 15 gem(s)Display dependencies as a visual tree:
$ gem why concurrent-ruby --tree
Dependency tree for concurrent-ruby:
rails (8.0.3)
├── activesupport = 8.0.3
│ └── activesupport (8.0.3) requires concurrent-ruby ~> 1.0, >= 1.3.1
│ └── concurrent-ruby ✓
actionpack (8.0.3)
├── activesupport = 8.0.3
│ └── activesupport (8.0.3) requires concurrent-ruby ~> 1.0, >= 1.3.1
│ └── concurrent-ruby ✓
Total: 10 root gem(s) depend on concurrent-rubyIf no gems depend on the specified gem:
$ gem why nonexistent-gem
No gems depend on nonexistent-gem| Option | Short | Description |
|---|---|---|
| (none) | Show full dependency chains (default) | |
--direct |
-d |
Show only direct dependencies |
--tree |
-t |
Display as a visual tree |
--json |
Output in JSON format | |
--help |
-h |
Show help message |
--verbose |
-V |
Verbose output |
- Builds a complete dependency graph of all installed gems
- Finds all paths (dependency chains) leading to the target gem
- Shows transitive dependencies (A depends on B, B depends on target)
- Groups results by root gems
- Displays the full chain:
root => intermediate => target
- Scans all installed gems on your system
- Checks both runtime and development dependencies
- Finds which gems directly depend on the specified gem
- Displays results with gem names, versions, and requirements
- Results are sorted alphabetically for easy reading
- Performs deep dependency analysis
- Builds a hierarchical tree structure
- Visualizes dependencies using tree characters (├──, └──, │)
- Shows the complete dependency path from root to target
- Makes it easy to understand complex dependency relationships
The gem is available as open source under the terms of the MIT License.