Gemfile

What is a .gemfile file?

The Ruby project's dependency manifest — Bundler reads this and installs every gem listed, pinning resolved versions in Gemfile.lock for reproducibility.

Safe format
Type Code
By André Arko / Yehuda Katz (Bundler)
MIME text/x-ruby

Drop any file to identify it

No upload. No signup. No sending your file halfway across the internet.
We tell you what it is, right here in your browser.

What is it

Every Ruby project past hello-world has a Gemfile at its root. It's Ruby's equivalent of `package.json` (Node), `requirements.txt` (Python), or `Cargo.toml` (Rust): a single file declaring which gems (Ruby libraries) the project depends on. Bundler reads this file, resolves a compatible set of versions, installs them, and writes the resolved versions to a Gemfile.lock that locks the entire dependency tree.

The syntax is a Ruby DSL — yes, the Gemfile is itself executable Ruby code. `source 'https://rubygems.org'` at the top declares the gem registry. `gem 'rails', '~> 7.1'` adds Rails with a pessimistic version constraint (>= 7.1, < 8.0). Gems can be grouped (`group :development, :test do ... end`) so production deploys skip dev-only dependencies. Versioned operators include `~>` (pessimistic), `>=` (minimum), and `=` (exact).

Gemfile and Gemfile.lock both belong in version control for applications. Gemfile.lock pins exact versions across machines so `bundle install` produces identical environments everywhere. `bundle update` upgrades dependencies within the constraints in Gemfile and rewrites the lock file. The pair is foundational to Ruby — every Ruby tool (Rails, Sinatra, Jekyll, Sidekiq) assumes you're using Bundler. The CLI is `bundle install`, `bundle exec`, `bundle update`.

Technical details
Full Name
Gemfile
MIME Type
text/x-ruby
Developer
André Arko / Yehuda Katz (Bundler)
Magic Bytes
N/A
Safety
.gemfile is a known, safe format.
What opens it
Any text editor
FREE All
VS Code
FREE All
RubyMine
JetBrains subscription All
FAQ
What's the difference between Gemfile and Gemfile.lock?
Gemfile is what you write — declared dependencies with version constraints. Gemfile.lock is what Bundler generates — the resolved, pinned versions of every gem (and every gem's dependencies, recursively). Both belong in git: Gemfile expresses intent, Gemfile.lock guarantees reproducibility.
Should I commit Gemfile.lock for libraries?
For applications: yes, always. For libraries published as gems: traditionally no, because users of your library shouldn't be locked to your specific dependency versions. Bundler 2 made this debatable — recent guidance leans toward committing it for libraries too, but treating it as a development convenience rather than a contract.
Why is the Gemfile written in Ruby?
Because Bundler is a Ruby tool and the simplest way to parse a config file in Ruby is to make it Ruby. The DSL approach lets you do conditional logic (`gem 'pg' if ENV['DATABASE_URL']`) which JSON or TOML can't easily express.
Related formats