Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundler is using a binstub that was created for a different gem.

When I run a rails console using

rails console

everything is fine.

When I run a rails console using

bundle exec rails console

I get the following warning

Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub my_gem` to work around a system/bundle conflict.

my_gem happens to be a gem that I've created that is completely unrelated and not used in the current project directory.

I've tried every solution in this question with no luck: Bundler is using a binstub that was created for a different gem

I would appreciate any guidance on removing this warning or help understanding how binstubs work so that I can figure out what's going on.

like image 954
johnsorrentino Avatar asked Feb 06 '15 23:02

johnsorrentino


1 Answers

Nowadays it's common for projects to have "specialized" versions of tools. E.g. in some projects the "rails" command may be expected to be run using "spring" (to start up faster).

So it's not uncommon to generate files in your project's 'bin' directory, and then use those versions when running commands, so e.g. instead of

bundle exec rails console

or

bundle exec spring rails console

you could simply expect the following to work correctly

bin/rails console

and not care whether the project needs spring or bundler or zeus or whatever.

So if you don't have 'bin/rails' in your project, you should generate one that suits the project, e.g. using

bin/rake rails:update:bin

If you don't already have bin/rake, you might have to use

bundle exec rake rails:update:bin

(so your bin/rake commands will also get a speedup from using spring)

Some people even put ./bin in their paths, so whenever they run rake (or whatever) they are actually running ./bin/rake if it exists.

Troubleshooting

  1. for project specific tasks, use bin/* files, creating them if needed (e.g. using special rake tasks like in Rails or using bundle binstub <gemname>) - usually those have Bundler specific lines that will make Bundler happy.

  2. for non-project gems (like your gem), find out where it is (e.g. which mygem) and check out it's contents - it's probably using e.g. "bundler/setup" which is confusing Bundler (because bundler expects a local Gemfile file). Maybe your gem is using bundler (it shouldn't if it's a "global" kind of tool and not a "project" tool).

  3. Also, if you're using them, check if tools like RVM and .rbenv are correctly adding their stuff to your bin files (they usually need to setup specific paths)

  4. If you still have questions, it's best to post the contents of the bin file causing problems - it's meant to be a plain Ruby file, so if there's something wrong, it's usually because of the file contents (and not anything else).

More info: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs

like image 192
Cezary Baginski Avatar answered Sep 30 '22 01:09

Cezary Baginski