Home

Gemfile

Gemfile is a manifest file used by Bundler to manage a Ruby application's gem dependencies. It specifies where to fetch gems (sources), the gems themselves, their version constraints, and optional groupings or platform requirements. The Gemfile is designed to be edited by developers, while Bundler resolves the dependencies and records the exact versions in Gemfile.lock to ensure reproducible installs across environments.

A typical Gemfile begins with a source line and may specify the Ruby version, for example:

source 'https://rubygems.org'

ruby '3.1.0'

gem 'rails', '~> 7.0'

gem 'pg', '>= 1.1', '< 2.0'

group :development, :test do

gem 'rspec-rails'

gem 'pry'

end

You may also specify platform-specific gems, or different gems for production or test.

Gemfile.lock is generated by Bundler and records the exact gem versions resolved from the constraints in

- bundle install: installs gems from the Gemfile, creating or updating Gemfile.lock

- bundle update: updates gems within the constraints and updates the lock file

- bundle exec <command>: runs a command in the context of the bundle

The Gemfile is commonly used in Ruby projects, including Rails apps, but it is a general mechanism

the
Gemfile.
The
lock
file
should
be
committed
to
version
control
to
guarantee
the
same
dependency
set
in
all
environments.
Bundler
commands
include:
for
dependency
management
in
Bundler.