25 Nov 2020 · Semaphore News

    How to use different Gemfiles with Bundler

    1 min read
    Contents

    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.

    Bundler supports passing an environment variable called BUNDLE_GEMFILE to all of its commands. Here is an example how we can tell it to use a file called Gemfile-rails4:

    BUNDLE_GEMFILE=Gemfile-rails4 bundle install –path vendor/bundle-rails4

    You can then run tests in the similar way:

    BUNDLE_GEMFILE=Gemfile-rails4 bundle exec rake spec

    On Semaphore, I recommend creating a new project with the same repo and using build commands tailored for the custom Gemfile.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Avatar
    Writen by:
    Marko Anastasov is a software engineer, author, and co-founder of Semaphore. He worked on building and scaling Semaphore from an idea to a cloud-based platform used by some of the world’s engineering teams.