Gemfile Builder (Ruby)

Generate a Gemfile for a Ruby or Rails project

Create a Bundler Gemfile with source, Ruby version, the Rails gem and database driver, plus common gems for authentication (Devise), background jobs (Sidekiq) and testing (RSpec) in the right groups. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What does the pessimistic operator ~> mean?

The ~> operator allows updates that do not change the leftmost specified part. ~> 7.2 permits any 7.x at or above 7.2, while ~> 7.2.2 permits 7.2.x only. It lets Bundler pick up bug-fix releases automatically while blocking breaking version jumps.

The Gemfile Builder generates a Bundler Gemfile for a Ruby or Rails project, with the right gems placed in the right groups. Pick your Ruby and Rails versions, your database, and toggles for authentication, background jobs and testing.

What a Gemfile actually contains

A Gemfile has three layers. First comes a source declaration pointing to RubyGems and a ruby version directive that locks the interpreter version Bundler enforces. Second comes the main gems — for a Rails app this means rails, a database driver, a web server (puma), and any runtime dependencies like redis or devise. Third come the grouped gems: development-only tools like rubocop and testing libraries like rspec or capybara go in group blocks so Bundler can install just what each environment needs.

How it works

The tool assembles these three layers based on your choices:

  • Rails vs plain Ruby. A Rails project gets the rails gem pinned with the pessimistic ~> operator, which allows bug-fix releases within the minor version without jumping to a breaking major. A plain Ruby project skips the Rails stack.
  • Database driver. Choose pg for PostgreSQL, mysql2 for MySQL or MariaDB, or sqlite3 for SQLite. The gem must match your config/database.yml adapter exactly or Rails raises a connection error at boot.
  • Optional gems. Toggling Devise adds authentication scaffolding; Sidekiq adds background-job processing with Redis as the queue backend. These are top-level gems because they run in all environments.
  • Test and development groups. RSpec (rspec-rails), FactoryBot, Capybara, and Selenium land in group :development, :test or group :test; rubocop and similar tools go in group :development. Production deploys skip these groups entirely.

The ~> operator is central to safe versioning: ~> 7.2 allows any 7.x from 7.2 up but blocks 8.0; ~> 7.2.2 restricts to 7.2.x only. This lets Bundler pick up patch releases automatically while keeping breaking version jumps out.

After generating your Gemfile

Save the output as Gemfile in your project root, then resolve and lock:

bundle install                                # resolves and writes Gemfile.lock
bundle install --without development test     # production deploy (skips dev/test groups)
bundle update rails                           # bump one gem within its ~> constraint

Gemfile.lock and why it matters

Commit Gemfile.lock for applications. It records the exact resolved version of every gem — direct and transitive — so every developer machine, CI runner, and production server installs identical code. Leave Gemfile.lock out of published gems (add it to .gitignore) so downstream applications can resolve their own consistent set.

Common pitfalls

MistakeWhat goes wrongFix
Database gem mismatchRails cannot connect at bootMatch gem to config/database.yml adapter
bootsnap without require: falseGem evaluation order issuesAlways use gem 'bootsnap', require: false
Dev tools outside groupsrubocop loads in productionPlace in group :development
Forgetting to commit lock fileDifferent gem versions per environmentAlways commit Gemfile.lock for apps