bundler Rails require different gem in development bundler Rails require different gem in development ruby-on-rails ruby-on-rails

bundler Rails require different gem in development


I've had the same problem and solved like this:

if ENV["RAILS_ENV"] == "development"  gem 'my_gem', :path => '~/apps/my_gem'else  gem 'my_gem', '1.0.0'end

then you can run RAILS_ENV=development bundle on your local machine and run any environment related command through RAILS_ENV=development bundle exec


Doing this defeats the purpose of using Bundler. The whole point is that the dependencies you're using are consistent no matter where your application is loaded, deliberately trying to circumvent that goal is just going to cause you problems.

What happens when your local version of that gem is different than the one released in Rubygems (perhaps because you forgot to release a new version?)? Your app may blow up and you won't be able to reproduce it in development, which is horrible.

As for why this isn't even conceivable to achieve with Bundler (at least now): what happens if the dependency versions for the Gem are different in the Rubygems version vs. the local version are different? Now your entire Gemfile.lock needs to have two completely different dependency graphs, and you're potentially introducing countless more points of failure in production that wouldn't exist in development.

That said, it's okay to temporarily change your Gemfile to the local version while making changes to the gem, but you should change it back and release a new version of the gem, then bundle update my_gem to update the Gemfile.lock accordingly.


it's probably that you have put gem 'my_gem' in somewhere else also, double check it