In Depth

Read the manual for an in-depth discussion of all of the options available in the Gemfile and how to use them.
Gemfile manual


Gemfiles require at least one gem source, in the form of the URL for a RubyGems server. There are shortcuts for the default gem server, so all of these sources are the same.
source :rubygems
source ""
source :rubyforge
source ""
source :gemcutter
source ""

Declare the gems that you need, including version numbers. Specify versions using the same syntax that RubyGems supports for dependencies.
gem "nokogiri"
gem "rails", "3.0.0.beta3"
gem "rack",  ">=1.0"
gem "thin",  "~>1.1"
Most of the version specifiers, like >= 1.0, are self-explanatory. The specifier ~> has a special meaning, best shown by example. ~> 2.0.3 is identical to >= 2.0.3 and < 2.1. ~> 2.1 is identical to >= 2.1 and < 3.0. ~> 2.2.beta will match prerelease versions like 2.2.beta.12.
RubyGems version specifiers
If a gem's main file is different than the gem name, specify how to require it. Or use false to prevent bundler to require it (but it will still install it and maintain dependencies). And for gems with several files to require, it's also possible to give an array to :require.
gem "rspec", :require => "spec"
gem "sqlite3"
gem "gem-release", :require => false
gem "redis", :require => ["redis/connection/hiredis", "redis"]
In order to require gems in your Gemfile, you will need to call Bundler.require in your application.
Learn More: Bundler.require
Git repositories are also valid gem sources, as long as the repo contains one or more valid gems. Specify what to check out with :tag, :branch, or :ref. The default is the master branch.
gem "nokogiri", :git => "", :branch => "1.4"

git "", :tag => "v0.13.4"
gem "thor"
If the git repository does not contain a .gemspec file, bundler will create a simple one, without any dependencies, executables or C extensions. This may work for simple gems, but not work for others. If there is no .gemspec, you probably shouldn't use the gem from git.
Learn More: Git
If you are actively developing a gem, perhaps checked out from Github, you can use the gem directly from its directory on your filesystem.
gem "nokogiri", :path => "~/sw/gems/nokogiri"

Dependencies can be placed into groups, to be ignored at install-time or required all at once.
gem "wirble", :group => :development
gem "ruby-debug", :group => [:development, :test]

group :test do
  gem "rspec"
Learn More: Groups
Edit this document on GitHub if you caught an error or noticed something was missing.