9

Why doesn't bundle exec spring work?

I am already calling bundle exec and that returns an error. I am okay calling bundle exec all the time. (This is the solution to the possible duplicate question).

I will not update my Gemfile via bundle update spring or uninstall a version of spring to make this work. I should not be forced to change my gem installation.

bundle binstubs spring isn't working either.

steve-air:finalcloud main$ spring -v
Spring version 1.3.5
steve-air:finalcloud main$ bundle exec spring -v
Spring version 1.3.4
steve-air:finalcloud main$ bundle exec spring
/Users/main/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:34:in `block in setup': You have already activated spring 1.3.5, but your Gemfile requires spring 1.3.4. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:19:in `setup'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.7/lib/bundler.rb:122:in `setup'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.7/lib/bundler/setup.rb:8:in `<top (required)>'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.5/lib/spring/commands.rb:33:in `<module:Spring>'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.5/lib/spring/commands.rb:4:in `<top (required)>'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.5/lib/spring/server.rb:9:in `<top (required)>'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
  from /Users/main/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'

To replicate:

  1. Have Ruby installed with rebenv.
  2. Uninstall all Spring gems.
  3. Install a lower version of Spring (such as 1.3.4).
  4. Make a new Rails app.
  5. Install a higher version of Spring (1.3.5 seems to have disappeared, but I replicated with 1.3.6).
  6. Follow the steps in my command line above.
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
s12chung
  • 1,718
  • 1
  • 14
  • 29
  • possible duplicate of [You have already activated X, but your Gemfile requires Y](http://stackoverflow.com/questions/6317980/you-have-already-activated-x-but-your-gemfile-requires-y) – Jorge de los Santos May 12 '15 at 19:01
  • 3
    It looks like the rails `core_ext` loads the newest `spring` version available before `bundler/setup` can run. It is only at this point in time it looks at your Gemfile and notices that you already have a newer version running than specified in your Gemfile. Not sure why it behaves differently when passed the `-v` option though. – Martin Konecny May 12 '15 at 21:11
  • You should run `rbenv shell `, before installing the GEM. Here it seems you have also installed **Spring 1.3.5** inside `rbenv shell ` – Abhi May 13 '15 at 11:24
  • having both versions inside the same ruby version seems fine with me @Abhi. `bundle exec` is supposed to handle it. @MartinKonecny. yeah.... it's weird how it's different. – s12chung May 13 '15 at 13:00
  • what is in your Gemfile and in your Gemfile.lock? – Mircea May 17 '15 at 19:40
  • can't copy and paste my client's stuff, but i added steps to replicate with a new app. thanks @Mircea – s12chung May 17 '15 at 21:38
  • when you install, do you install directly via gem or do you let bundler do this? Is the Gemfile and the Gemfile.lock in the rails app containing the older version? – Mircea May 17 '15 at 23:08
  • i installed spring via gem. just Gemfile.lock containg the older version. thanks again @Mircea. The Gemfile has no version number specified. – s12chung May 17 '15 at 23:58
  • there are a couple of things here. one is installing via gem via letting bundler install the gems from the Gemfile. The 2nd thing is the binstubs that are generated. these are at gem level and at rvm level. So what I guess is happening is that the system level gem is being picked up instead of what you've specified in the gemfile. Normally this should NOT happen via bundle exec. But rails is "special": http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/ – Mircea May 18 '15 at 17:42
  • from the above: In short, the rails executable does a bunch of work to guarantee that your application's bootstrapping logic runs before any dependencies are loaded, and it uses Kernel#exec to purge the current process of any already-loaded gems. This is not something that general-purpose gems can or should do, and it's an open question whether making the rails executable work without bundle exec sufficiently muddies the waters with regard to other gems as to render the benefit not worth it. – Mircea May 18 '15 at 17:43
  • 1
    scroll to the bottom of this: https://github.com/rails/spring/issues/295 – Mircea May 18 '15 at 17:50
  • yeah... it seems that Spring is special.... i probably should have looked in the GitHub repo earlier.... thanks @Mircea :) – s12chung May 18 '15 at 17:57

3 Answers3

7

After a bit of exploration there seem there could be a couple of things in play here:

  1. system installed gems via bundler installed gems and the special behavior rails has
  2. generated binstubs at rvm and bundle level
  3. weird behavior in Spring 1.3.5

The root cause of the issue seems to be https://github.com/rails/spring/issues/295 which was fixed in 1.3.6. See: https://github.com/rails/spring/blob/master/CHANGELOG.md#136

Sadly, it turns out you cannot workaround this with the constraints the author specified in the question.

Mircea
  • 10,216
  • 2
  • 30
  • 46
3

This is a bug in Spring that has been fixed in version 1.3.6.

i will not update my Gemfile (via bundle update spring) or uninstall a version of spring to make this work---i should not be forced to change my gem installation.

Unfortunately, these are the only known workarounds in versions earlier than 1.3.6.

Tim Moore
  • 8,958
  • 2
  • 23
  • 34
  • that's basically the conclusion that was reached in the comments above :) – Mircea May 18 '15 at 22:23
  • Yep... Mircea if you want to rephrase your comments as an answer I'll happily upvote it! – Tim Moore May 19 '15 at 07:34
  • :) That's okay. To me the problem seems very specific.Just glad I could help – Mircea May 19 '15 at 13:40
  • added my own comment after I've read the rules around how the bounty points work (i.e. you lose the points if not awarded - was under the impression that you get them back, but seems that's not the case) – Mircea May 20 '15 at 18:53
1

Just uninstall the older version of the spring gem

gem uninstall spring
Kannan S
  • 2,459
  • 1
  • 17
  • 17