Home / Rails Style Guide Topics

Bundler Practices for Rails Projects

The documentation that used to be at this address is no longer published, and its source was never released under an open license, so it is not reproduced here. This page is an independent guide to the same topic, written for this archive. It is not the project's documentation and is not affiliated with its authors.

Bundler is what makes "it works on my machine" mean "it works on every machine". Used well, it gives a Rails team reproducible installs and calm upgrades. Used carelessly, it produces sprawling version pins and surprise breakages.

Commit the lockfile

For applications, always commit Gemfile.lock. It records the exact versions that were tested, so production, CI and every developer run the same code. (Library gems are different, but a Rails app is an application.)

Constrain versions sensibly

gem "rails", "~> 7.1.0"     # allow patch releases only
gem "sidekiq", "~> 7.2"      # allow minor releases within 7.x
gem "nokogiri"                # trust the lockfile
gem "some_fragile_gem", "1.4.2" # exact pin, with a comment saying why

Updating without drama

  1. Update one gem at a time: bundle update --conservative sidekiq changes only that gem and the minimum of its dependencies.
  2. Read the changelog for anything beyond a patch release.
  3. Run the full test suite before merging.
  4. Avoid a bare bundle update on a large app. It changes everything at once and makes failures hard to trace.

Running commands

Use bundle exec, or the binstubs in bin/, so commands use the bundled versions:

bin/rails db:migrate
bundle exec rspec
bundle exec rubocop

In CI

More on Rails Style Guide Topics

Explore the archive