How to use different Gemfiles with Bundler

Normally when you’re working with a Ruby project with Bundler you write a file called Gemfile, run bundle install and then invoke various commands with the bundle exec prefix. However what if you would like to be able to work with different versions of gems over a longer period of time? In that case being able to use multiple Gemfiles within a single branch can help.

Imported from Disqus

Guest • 6 years ago • edited

Marko - I’m having trouble building a gem via Semaphore, specifically the Gemfile.

As is typical for gems, I have .gemspec file to specify dependencies, rather than a Gemfile. More specifically, I have a Gemfile, but it only contains a source and a gemspec declaration.

I’m trying to do a basic build, as in

bundle install --deployment --path vendor/bundle
bundle exec rake

But it can’t locate a Gemfile. No combination of BUNDLE_GEMFILE= env var setting or --gemfile flag for the bundle install command appear to work with my_gem.gemspec.

Am I missing something obvious?

Thanks.

Marko Anastasov Mod Guest6 years ago

Hi Kevin, I believe the answer is simple: gemspec is not a Gemfile. You need to have a Gemfile for your gem which would forward Bundler to the gemspec. See for example https://github.com/rendered….