60

I am getting the following error when doing bundle install

Make sure that `gem install couchbase -v '1.3.3'` succeeds before bundling.

Now, i have not included this gem in the Gemfile, so it's coming from some dependency. How can i figure out which gem is dependent on this couchbase gem?

Since bundle install is failing and I don't have Gemfile.lock to figure out this dependency.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Mohit Verma
  • 2,019
  • 7
  • 25
  • 33

2 Answers2

85

gem dependency (with no args) should show you all gems from current system with their dependencies.

bundle exec gem dependency will show you for the current Gemfile

Edit:

You can also do gem dependency -R (or just dep instead of dependency) if you want to find out which gems use specific (or all) gems.

For deeper dependencies I'd parse output (regex maybe?) of first gem dependencies, pick gem's names and call gem dep on each of them, but that's just a loose idea.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
zrl3dx
  • 7,699
  • 3
  • 25
  • 35
  • Thnx. This answers my question. Strange but 'gem dependency' is showing that no gem is dependent on 'couchbase'. Any idea why bundle install is trying to install it even though none of the gem is dependent on it ? – Mohit Verma Sep 27 '13 at 12:42
  • Frankly, I don't know, what happens if you w'd try installing that gem by hand? Also, can you post your Gemfile? – zrl3dx Sep 27 '13 at 12:42
  • I can install gemfile on local, but while deployment or running CI it will bomb. – Mohit Verma Sep 27 '13 at 12:47
  • "gem dependency" only shows 1st level of dependency, any idea how to see nested dependencies ? – Mohit Verma Sep 27 '13 at 12:47
  • 2
    @MohitVerma why don't you take a look at your local `Gemfile.lock`? – Stefan Sep 27 '13 at 12:52
  • @MohitVerma: so you **do** have `Gemfile.lock`, why won't check it? – zrl3dx Sep 27 '13 at 12:53
  • @Stefan, bundle install is failing, so i am not able to generate Gemfile.lock – Mohit Verma Sep 27 '13 at 13:10
  • You said *"I can install gemfile on local"* – Stefan Sep 27 '13 at 13:11
  • Somehow, not able to install it locally also. couchbase gem needs few more things on machine :( Any other option ? – Mohit Verma Sep 28 '13 at 08:39
  • 14
    `gem dependency` has nothing to do with your current `Gemfile`. It just looks at the installed gems on the system. – Mark Reed Oct 19 '16 at 16:02
  • If the dependency generation fails, you don't get a `Gemfile.lock` to look at. All that happens is that "bundle install" fails trying to install some random gem that is not listed in your Gemfile. In this situation, as far as I can tell, the only way to find out *why* bundle was even trying to install that gem in the first place is to somehow get all the gems in the Gemfile installed successfully so you can run `gem dependency --reverse-dependencies` on it. – Mark Reed Dec 12 '16 at 20:43
  • `gem dependency` is also showing me dependencies for things that are NOT in `~/Gemfile`. This makes the results very unhelpful. – William Entriken Feb 16 '17 at 18:45
  • 5
    `bundle exec gem dependency` will use the`Gemfile` gems. – Eliot Sykes Dec 18 '18 at 11:03
27

You can also use bundler to create a dependency graph.

Install graphviz:

gem install ruby-graphviz

and then:

bundle viz

Here are an example of a newly created Rails app:

Rails app dependency graph

You can also play with the options:

bundle help viz 
Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
  • 3
    If you don’t have Graphviz but you do have Homebrew, you can `brew install graphviz`. – duozmo May 12 '16 at 15:59
  • `bundle viz -vR` will create the dependency graph with the gem version and the required dependency version – Sathish Jun 27 '20 at 19:46
  • it's great but the generated png file is hardly readable. One would have to guess what's written there. – Masroor Sep 22 '21 at 12:24