Gemfile 5
Gemfile 5
NAME
Gemfile - A format for describing gem dependencies for Ruby programs
SYNOPSIS
A Gemfile describes the gem dependencies required to execute associated
Ruby code.
Place the Gemfile in the root of the directory containing the associ-
ated code. For instance, in a Rails application, place the Gemfile in
the same directory as the Rakefile.
SYNTAX
A Gemfile is evaluated as Ruby code, in a context which makes available
a number of methods used to describe the gem requirements.
GLOBAL SOURCES
At the top of the Gemfile, add a line for the Rubygems source that con-
tains the gems listed in the Gemfile.
source "https://rubygems.org"
CREDENTIALS
Some gem sources require a username and password. Use bundle config(1)
bundle-config.1.html to set the username and password for any of the
sources that need it. The command must be run once on each computer
that will install the Gemfile, but this keeps the credentials from
being stored in plain text in version control.
Credentials in the source URL will take precedence over credentials set
using config.
RUBY
If your application requires a specific Ruby version or engine, specify
your requirements using the ruby method, with the following arguments.
All parameters are OPTIONAL unless otherwise specified.
VERSION (required)
The version of Ruby that your application requires. If your application
requires an alternate Ruby engine, such as JRuby, Rubinius or Truf-
fleRuby, this should be the Ruby version that the engine is compatible
with.
ruby "1.9.3"
ENGINE
Each application may specify a Ruby engine. If an engine is specified,
an engine version must also be specified.
ENGINE VERSION
Each application may specify a Ruby engine version. If an engine ver-
sion is specified, an engine must also be specified. If the engine is
"ruby" the engine version specified must match the Ruby version.
PATCHLEVEL
Each application may specify a Ruby patchlevel.
ruby "2.0.0", :patchlevel => "247"
GEMS
Specify gem requirements using the gem method, with the following argu-
ments. All parameters are OPTIONAL unless otherwise specified.
NAME (required)
For each gem requirement, list a single gem line.
gem "nokogiri"
VERSION
Each gem MAY have one or more version specifiers.
REQUIRE AS
Each gem MAY specify files that should be used when autorequiring via
Bundler.require. You may pass an array with multiple files or true if
file you want required has same name as gem or false to prevent any
file from being autorequired.
The argument defaults to the name of the gem. For example, these are
identical:
gem "nokogiri"
gem "nokogiri", :require => "nokogiri"
gem "nokogiri", :require => true
GROUPS
Each gem MAY specify membership in one or more groups. Any gem that
does not specify membership in any group is placed in the default
group.
gem "rspec", :group => :test
gem "wirble", :groups => [:development, :test]
The Bundler runtime allows its two main methods, Bundler.setup and
Bundler.require, to limit their impact to particular groups.
The Bundler CLI allows you to specify a list of groups whose gems bun-
dle install should not install with the --without option. To specify
multiple groups to ignore, specify a list of groups separated by spa-
ces.
After running bundle install --without test, bundler will remember that
you excluded the test group in the last installation. The next time you
run bundle install, without any --without option, bundler will recall
it.
Note that on bundle install, bundler downloads and evaluates all gems,
in order to create a single canonical list of all of the required gems
and their dependencies. This means that you cannot list different ver-
sions of the same gems in different groups. For more details, see
Understanding Bundler http://bundler.io/rationale.html.
PLATFORMS
If a gem should only be used in a particular platform or set of plat-
forms, you can specify them. Platforms are essentially identical to
groups, except that you do not need to use the --without install-
time
flag to exclude groups of gems for other platforms.
x64_mingw
Windows 64 bit 'mingw32' platform (aka RubyInstaller x64)
rbx Rubinius
jruby JRuby
truffleruby
TruffleRuby
mswin Windows
You can restrict further by platform and version for all platforms
except for rbx, jruby, truffleruby and mswin.
ruby_23
ruby 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
mri 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
mingw 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
x64_mingw
2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
SOURCE
You can select an alternate Rubygems repository for a gem using the
':source' option.
This forces the gem to be loaded from this source and ignores any
global sources declared at the top level of the file. If the gem does
not exist in this source, it will not be installed.
Bundler will search for child dependencies of this gem by first looking
in the source selected for the parent, but if they are not found there,
it will fall back on global sources using the ordering described in
SOURCE PRIORITY.
Using the :source option for an individual gem will also make that
source available as a possible global source for any other gems which
do not specify explicit sources. Thus, when adding gems with explicit
sources, it is recommended that you also ensure all other gems in the
Gemfile are using explicit sources.
GIT
If necessary, you can specify that a gem is located at a particular git
repository using the :git parameter. The repository can be accessed via
several protocols:
HTTP(S)
gem "rails", :git => "https://github.com/rails/rails.git"
If using SSH, the user that you use to run bundle install MUST have the
appropriate keys available in their $HOME/.ssh.
The group, platforms, and require options are available and behave
exactly the same as they would for a normal gem.
A git repository SHOULD have at least one file, at the root of the
directory containing the gem, with the extension .gemspec. This file
MUST contain a valid gem specification, as expected by the gem build
command.
If a git repository does have a .gemspec for the gem you attached it
to, a version specifier, if provided, means that the git repository is
only valid if the .gemspec specifies a version matching the version
specifier. If not, bundler will print a warning.
If a git repository does not have a .gemspec for the gem you attached
it to, a version specifier MUST be provided. Bundler will use this ver-
sion in the simple .gemspec it creates.
For example:
submodules
For reference, a git submodule
https://git-scm.com/book/en/v2/Git-Tools-Submodules lets you
have another git repository within a subfolder of your reposi-
tory. Specify :submodules => true to cause bundler to expand any
submodules included in the git repository
GIT SOURCE
A custom git source can be defined via the git_source method. Provide
the source's name as an argument, and a block which receives a single
argument and interpolates it into a string to return the full repo
address:
git_source(:stash){ |repo_name|
"https://stash.corp.acme.pl/#{repo_name}.git" }
gem 'rails', :stash => 'forks/rails'
GITHUB
NOTE: This shorthand should be avoided until Bundler 2.0, since it cur-
rently expands to an insecure git:// URL. This allows a man-in-the-mid-
dle attacker to compromise your system.
If the git repository you want to use is hosted on GitHub and is pub-
lic, you can use the :github shorthand to specify the github username
and repository name (without the trailing ".git"), separated by a
slash. If both the username and repository name are the same, you can
omit one.
Is equivalent to:
BITBUCKET
If the git repository you want to use is hosted on Bitbucket and is
public, you can use the :bitbucket shorthand to specify the bitbucket
username and repository name (without the trailing ".git"), separated
by a slash. If both the username and repository name are the same, you
can omit one.
PATH
You can specify that a gem is located in a particular location on the
file system. Relative paths are resolved relative to the directory con-
taining the Gemfile.
Similar to the semantics of the :git option, the :path option requires
that the directory in question either contains a .gemspec for the gem,
or that you specify an explicit version that bundler should use.
Unlike :git, bundler does not compile C extensions for gems specified
as paths.
gem "rails", :path => "vendor/rails"
If you would like to use multiple local gems directly from the filesys-
tem, you can set a global path option to the path containing the gem's
files. This will automatically load gemspec files from subdirectories.
path 'components' do
gem 'admin_ui'
gem 'public_ui'
end
source "https://gems.example.com" do
gem "some_internal_gem"
gem "another_internal_gem"
end
git "https://github.com/rails/rails.git" do
gem "activesupport"
gem "actionpack"
end
platforms :ruby do
gem "ruby-debug"
gem "sqlite3"
end
In the case of the group block form the :optional option can be given
to prevent a group from being installed unless listed in the --with
option given to the bundle install command.
In the case of the git block form, the :ref, :branch, :tag, and :sub-
modules options may be passed to the git method, and all gems in the
block will inherit those options.
INSTALL_IF
The install_if method allows gems to be installed based on a proc or
lambda. This is especially useful for optional gems that can only be
used if certain software is installed or some other conditions are met.
GEMSPEC
The .gemspec http://guides.rubygems.org/specification-reference/ file
is where you provide metadata about your gem to Rubygems. Some required
Gemspec attributes include the name, description, and homepage of your
gem. This is also where you specify the dependencies your gem needs to
run.
If you wish to use Bundler to help install dependencies for a gem while
it is being developed, use the gemspec method to pull in the dependen-
cies listed in the .gemspec file.
The gemspec method supports optional :path, :glob, :name, and :develop-
ment_group options, which control where bundler looks for the .gemspec,
the glob it uses to look for the gemspec (defaults to: "{,,/*}.gem-
spec"), what named .gemspec it uses (if more than one is present), and
which group development dependencies are included in.
SOURCE PRIORITY
When attempting to locate a gem to satisfy a gem requirement, bundler
uses the following priority order: