2018-11-02 19:07:56 -04:00
|
|
|
GEMFILE(5) GEMFILE(5)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
NAME
|
|
|
|
Gemfile - A format for describing gem dependencies for Ruby programs
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
SYNOPSIS
|
|
|
|
A Gemfile describes the gem dependencies required to execute associated
|
2018-11-02 19:07:56 -04:00
|
|
|
Ruby code.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
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.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
SYNTAX
|
|
|
|
A Gemfile is evaluated as Ruby code, in a context which makes available
|
2018-11-02 19:07:56 -04:00
|
|
|
a number of methods used to describe the gem requirements.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
GLOBAL SOURCES
|
|
|
|
At the top of the Gemfile, add a line for the Rubygems source that con-
|
|
|
|
tains the gems listed in the Gemfile.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source "https://rubygems.org"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It is possible, but not recommended as of Bundler 1.7, to add multiple
|
2019-04-14 02:01:35 -04:00
|
|
|
global source lines. Each of these sources MUST be a valid Rubygems
|
2018-11-02 19:07:56 -04:00
|
|
|
repository.
|
|
|
|
|
|
|
|
Sources are checked for gems following the heuristics described in
|
2019-04-14 02:01:35 -04:00
|
|
|
SOURCE PRIORITY. If a gem is found in more than one global source,
|
2018-11-02 19:07:56 -04:00
|
|
|
Bundler will print a warning after installing the gem indicating which
|
|
|
|
source was used, and listing the other sources where the gem is avail-
|
|
|
|
able. A specific source can be selected for gems that need to use a
|
2019-04-14 02:01:35 -04:00
|
|
|
non-standard repository, suppressing this warning, by using the :source
|
|
|
|
option or a source block.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
CREDENTIALS
|
2018-11-02 19:07:56 -04:00
|
|
|
Some gem sources require a username and password. Use bundle config(1)
|
2019-04-14 02:01:35 -04:00
|
|
|
bundle-config.1.html to set the username and password for any of the
|
2018-11-02 19:07:56 -04:00
|
|
|
sources that need it. The command must be run once on each computer
|
2019-04-14 02:01:35 -04:00
|
|
|
that will install the Gemfile, but this keeps the credentials from
|
|
|
|
being stored in plain text in version control.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bundle config gems.example.com user:password
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For some sources, like a company Gemfury account, it may be easier to
|
|
|
|
include the credentials in the Gemfile as part of the source URL.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source "https://user:password@gems.example.com"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Credentials in the source URL will take precedence over credentials set
|
2019-04-14 02:01:35 -04:00
|
|
|
using config.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
RUBY
|
2018-11-02 19:07:56 -04:00
|
|
|
If your application requires a specific Ruby version or engine, specify
|
2019-04-14 02:01:35 -04:00
|
|
|
your requirements using the ruby method, with the following arguments.
|
|
|
|
All parameters are OPTIONAL unless otherwise specified.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
VERSION (required)
|
2018-11-02 19:07:56 -04:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
ENGINE
|
|
|
|
Each application may specify a Ruby engine. If an engine is specified,
|
|
|
|
an engine version must also be specified.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
What exactly is an Engine? - A Ruby engine is an implementation of the
|
|
|
|
Ruby language.
|
|
|
|
|
|
|
|
o For background: the reference or original implementation of the
|
|
|
|
Ruby programming language is called Matz's Ruby Interpreter
|
2019-04-14 02:01:35 -04:00
|
|
|
https://en.wikipedia.org/wiki/Ruby_MRI, or MRI for short. This is
|
2018-11-02 19:07:56 -04:00
|
|
|
named after Ruby creator Yukihiro Matsumoto, also known as Matz.
|
|
|
|
MRI is also known as CRuby, because it is written in C. MRI is the
|
|
|
|
most widely used Ruby engine.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
o Other implementations https://www.ruby-lang.org/en/about/ of Ruby
|
2018-11-02 19:07:56 -04:00
|
|
|
exist. Some of the more well-known implementations include Rubinius
|
2019-04-14 02:01:35 -04:00
|
|
|
https://rubinius.com/, and JRuby http://jruby.org/. Rubinius is an
|
|
|
|
alternative implementation of Ruby written in Ruby. JRuby is an
|
2019-09-18 02:28:08 -04:00
|
|
|
implementation of Ruby on the JVM, short for Java Virtual Machine.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
ENGINE VERSION
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2019-04-14 02:01:35 -04:00
|
|
|
"ruby" the engine version specified must match the Ruby version.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ruby "1.8.7", :engine => "jruby", :engine_version => "1.6.7"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
PATCHLEVEL
|
|
|
|
Each application may specify a Ruby patchlevel.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ruby "2.0.0", :patchlevel => "247"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
GEMS
|
|
|
|
Specify gem requirements using the gem method, with the following argu-
|
|
|
|
ments. All parameters are OPTIONAL unless otherwise specified.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
NAME (required)
|
|
|
|
For each gem requirement, list a single gem line.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "nokogiri"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
VERSION
|
|
|
|
Each gem MAY have one or more version specifiers.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "nokogiri", ">= 1.4.2"
|
|
|
|
gem "RedCloth", ">= 4.1.0", "< 4.2.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
REQUIRE AS
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
file from being autorequired.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "redis", :require => ["redis/connection/hiredis", "redis"]
|
|
|
|
gem "webmock", :require => false
|
2019-08-08 06:08:53 -04:00
|
|
|
gem "byebug", :require => true
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
The argument defaults to the name of the gem. For example, these are
|
2018-11-02 19:07:56 -04:00
|
|
|
identical:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "nokogiri"
|
|
|
|
gem "nokogiri", :require => "nokogiri"
|
|
|
|
gem "nokogiri", :require => true
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
GROUPS
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
group.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rspec", :group => :test
|
|
|
|
gem "wirble", :groups => [:development, :test]
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
The Bundler runtime allows its two main methods, Bundler.setup and
|
2019-04-14 02:01:35 -04:00
|
|
|
Bundler.require, to limit their impact to particular groups.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# setup adds gems to Ruby's load path
|
|
|
|
Bundler.setup # defaults to all groups
|
|
|
|
require "bundler/setup" # same as Bundler.setup
|
|
|
|
Bundler.setup(:default) # only set up the _default_ group
|
|
|
|
Bundler.setup(:test) # only set up the _test_ group (but `not` _default_)
|
|
|
|
Bundler.setup(:default, :test) # set up the _default_ and _test_ groups, but no others
|
|
|
|
|
|
|
|
# require requires all of the gems in the specified groups
|
|
|
|
Bundler.require # defaults to the _default_ group
|
|
|
|
Bundler.require(:default) # identical
|
|
|
|
Bundler.require(:default, :test) # requires the _default_ and _test_ groups
|
|
|
|
Bundler.require(:test) # requires the _test_ group
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
The Bundler CLI allows you to specify a list of groups whose gems bun-
|
2019-08-14 09:58:18 -04:00
|
|
|
dle install should not install with the without configuration.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
To specify multiple groups to ignore, specify a list of groups sepa-
|
2019-08-14 09:58:18 -04:00
|
|
|
rated by spaces.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 09:58:18 -04:00
|
|
|
bundle config set without test
|
|
|
|
bundle config set without development test
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
Also, calling Bundler.setup with no parameters, or calling require
|
|
|
|
"bundler/setup" will setup all groups except for the ones you excluded
|
2019-04-14 02:01:35 -04:00
|
|
|
via --without (since they are not available).
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2019-04-14 02:01:35 -04:00
|
|
|
Understanding Bundler https://bundler.io/rationale.html.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
PLATFORMS
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
flag to exclude groups of gems for other platforms.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
There are a number of Gemfile platforms:
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
ruby C Ruby (MRI), Rubinius or TruffleRuby, but NOT Windows
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
mri Same as ruby, but only C Ruby (MRI)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
mingw Windows 32 bit 'mingw32' platform (aka RubyInstaller)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
x64_mingw
|
2018-11-02 19:07:56 -04:00
|
|
|
Windows 64 bit 'mingw32' platform (aka RubyInstaller x64)
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
rbx Rubinius
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
jruby JRuby
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
truffleruby
|
2018-11-02 19:07:56 -04:00
|
|
|
TruffleRuby
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
mswin Windows
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
You can restrict further by platform and version for all platforms
|
2019-04-14 02:01:35 -04:00
|
|
|
except for rbx, jruby, truffleruby and mswin.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
To specify a version in addition to a platform, append the version num-
|
|
|
|
ber without the delimiter to the platform. For example, to specify that
|
|
|
|
a gem should only be used on platforms with Ruby 2.3, use:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ruby_23
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The full list of platforms and supported versions includes:
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
ruby 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
mri 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
mingw 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
x64_mingw
|
2019-01-04 08:10:58 -05:00
|
|
|
2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
As with groups, you can specify one or more platforms:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "weakling", :platforms => :jruby
|
|
|
|
gem "ruby-debug", :platforms => :mri_18
|
|
|
|
gem "nokogiri", :platforms => [:mri_18, :jruby]
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
All operations involving groups (bundle install bundle-install.1.html,
|
|
|
|
Bundler.setup, Bundler.require) behave exactly the same as if any
|
2018-11-02 19:07:56 -04:00
|
|
|
groups not matching the current platform were explicitly excluded.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
SOURCE
|
2019-09-18 02:28:08 -04:00
|
|
|
You can select an alternate Rubygems repository for a gem using the
|
2018-11-02 19:07:56 -04:00
|
|
|
':source' option.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "some_internal_gem", :source => "https://gems.example.com"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
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,
|
2019-09-18 02:28:08 -04:00
|
|
|
it will fall back on global sources using the ordering described in
|
2019-04-14 02:01:35 -04:00
|
|
|
SOURCE PRIORITY.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
Selecting a specific source repository this way also suppresses the
|
2019-04-14 02:01:35 -04:00
|
|
|
ambiguous gem warning described above in GLOBAL SOURCES (#source).
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
Gemfile are using explicit sources.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
GIT
|
2018-11-02 19:07:56 -04:00
|
|
|
If necessary, you can specify that a gem is located at a particular git
|
2019-04-14 02:01:35 -04:00
|
|
|
repository using the :git parameter. The repository can be accessed via
|
2018-11-02 19:07:56 -04:00
|
|
|
several protocols:
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
HTTP(S)
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rails", :git => "https://github.com/rails/rails.git"
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
SSH gem "rails", :git => "git@github.com:rails/rails.git"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
git gem "rails", :git => "git://github.com/rails/rails.git"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
If using SSH, the user that you use to run bundle install MUST have the
|
|
|
|
appropriate keys available in their $HOME/.ssh.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
NOTE: http:// and git:// URLs should be avoided if at all possible.
|
|
|
|
These protocols are unauthenticated, so a man-in-the-middle attacker
|
|
|
|
can deliver malicious code and compromise your system. HTTPS and SSH
|
2018-11-02 19:07:56 -04:00
|
|
|
are strongly preferred.
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
The group, platforms, and require options are available and behave
|
2019-04-14 02:01:35 -04:00
|
|
|
exactly the same as they would for a normal gem.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2019-04-14 02:01:35 -04:00
|
|
|
command.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
If a git repository does not have a .gemspec, bundler will attempt to
|
2018-11-02 19:07:56 -04:00
|
|
|
create one, but it will not contain any dependencies, executables, or C
|
2019-09-18 02:28:08 -04:00
|
|
|
extension compilation instructions. As a result, it may fail to prop-
|
2018-11-02 19:07:56 -04:00
|
|
|
erly integrate into your application.
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
specifier. If not, bundler will print a warning.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rails", "2.3.8", :git => "https://github.com/rails/rails.git"
|
|
|
|
# bundle install will fail, because the .gemspec in the rails
|
|
|
|
# repository's master branch specifies version 3.0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
If a git repository does not have a .gemspec for the gem you attached
|
2019-04-14 02:01:35 -04:00
|
|
|
it to, a version specifier MUST be provided. Bundler will use this ver-
|
|
|
|
sion in the simple .gemspec it creates.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
Git repositories support a number of additional options.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
branch, tag, and ref
|
2019-09-18 02:28:08 -04:00
|
|
|
You MUST only specify at most one of these options. The default
|
2019-07-10 11:26:55 -04:00
|
|
|
is :branch => "master". For example:
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
gem "rails", :git => "https://github.com/rails/rails.git",
|
2019-07-10 11:26:55 -04:00
|
|
|
:branch => "5-0-stable"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
gem "rails", :git => "https://github.com/rails/rails.git", :tag
|
2019-07-10 11:26:55 -04:00
|
|
|
=> "v5.0.0"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
gem "rails", :git => "https://github.com/rails/rails.git", :ref
|
2019-07-10 11:26:55 -04:00
|
|
|
=> "4aded"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
submodules
|
2019-09-18 02:28:08 -04:00
|
|
|
For reference, a git submodule
|
2019-04-14 02:01:35 -04:00
|
|
|
https://git-scm.com/book/en/v2/Git-Tools-Submodules lets you
|
2019-09-18 02:28:08 -04:00
|
|
|
have another git repository within a subfolder of your reposi-
|
2019-04-14 02:01:35 -04:00
|
|
|
tory. Specify :submodules => true to cause bundler to expand any
|
2018-11-02 19:07:56 -04:00
|
|
|
submodules included in the git repository
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
If a git repository contains multiple .gemspecs, each .gemspec repre-
|
|
|
|
sents a gem located at the same place in the file system as the .gem-
|
2019-04-14 02:01:35 -04:00
|
|
|
spec.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|~rails [git root]
|
|
|
|
| |-rails.gemspec [rails gem located here]
|
|
|
|
|~actionpack
|
|
|
|
| |-actionpack.gemspec [actionpack gem located here]
|
|
|
|
|~activesupport
|
|
|
|
| |-activesupport.gemspec [activesupport gem located here]
|
|
|
|
|...
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
To install a gem located in a git repository, bundler changes to the
|
|
|
|
directory containing the gemspec, runs gem build name.gemspec and then
|
2019-04-14 02:01:35 -04:00
|
|
|
installs the resulting gem. The gem build command, which comes standard
|
2019-09-18 02:28:08 -04:00
|
|
|
with Rubygems, evaluates the .gemspec in the context of the directory
|
2018-11-02 19:07:56 -04:00
|
|
|
in which it is located.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
GIT SOURCE
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2019-04-14 02:01:35 -04:00
|
|
|
address:
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
git_source(:stash){ |repo_name| "https://stash.corp.acme.pl/#{repo_name}.git" }
|
|
|
|
gem 'rails', :stash => 'forks/rails'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In addition, if you wish to choose a specific branch:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rails", :stash => "forks/rails", :branch => "branch_name"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
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-
|
2018-11-02 19:07:56 -04:00
|
|
|
dle attacker to compromise your system.
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
omit one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rails", :github => "rails/rails"
|
|
|
|
gem "rails", :github => "rails"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Are both equivalent to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rails", :git => "git://github.com/rails/rails.git"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Since the github method is a specialization of git_source, it accepts a
|
|
|
|
:branch named argument.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
GIST
|
2018-11-02 19:07:56 -04:00
|
|
|
If the git repository you want to use is hosted as a Github Gist and is
|
2019-09-18 02:28:08 -04:00
|
|
|
public, you can use the :gist shorthand to specify the gist identifier
|
2018-11-02 19:07:56 -04:00
|
|
|
(without the trailing ".git").
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "the_hatch", :gist => "4815162342"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Is equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "the_hatch", :git => "https://gist.github.com/4815162342.git"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
Since the gist method is a specialization of git_source, it accepts a
|
2019-04-14 02:01:35 -04:00
|
|
|
:branch named argument.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
BITBUCKET
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
can omit one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rails", :bitbucket => "rails/rails"
|
|
|
|
gem "rails", :bitbucket => "rails"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Are both equivalent to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rails", :git => "https://rails@bitbucket.org/rails/rails.git"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
Since the bitbucket method is a specialization of git_source, it
|
2019-04-14 02:01:35 -04:00
|
|
|
accepts a :branch named argument.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
PATH
|
2019-09-18 02:28:08 -04:00
|
|
|
You can specify that a gem is located in a particular location on the
|
2018-11-02 19:07:56 -04:00
|
|
|
file system. Relative paths are resolved relative to the directory con-
|
2019-04-14 02:01:35 -04:00
|
|
|
taining the Gemfile.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
Similar to the semantics of the :git option, the :path option requires
|
|
|
|
that the directory in question either contains a .gemspec for the gem,
|
2018-11-02 19:07:56 -04:00
|
|
|
or that you specify an explicit version that bundler should use.
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
Unlike :git, bundler does not compile C extensions for gems specified
|
2018-11-02 19:07:56 -04:00
|
|
|
as paths.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gem "rails", :path => "vendor/rails"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If you would like to use multiple local gems directly from the filesys-
|
2019-09-18 02:28:08 -04:00
|
|
|
tem, you can set a global path option to the path containing the gem's
|
|
|
|
files. This will automatically load gemspec files from subdirectories.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
path 'components' do
|
|
|
|
gem 'admin_ui'
|
|
|
|
gem 'public_ui'
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
BLOCK FORM OF SOURCE, GIT, PATH, GROUP and PLATFORMS
|
|
|
|
The :source, :git, :path, :group, and :platforms options may be applied
|
2018-11-02 19:07:56 -04:00
|
|
|
to a group of gems by using block form.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
group :development, :optional => true do
|
|
|
|
gem "wirble"
|
|
|
|
gem "faker"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In the case of the group block form the :optional option can be given
|
2019-04-14 02:01:35 -04:00
|
|
|
to prevent a group from being installed unless listed in the --with
|
|
|
|
option given to the bundle install command.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
block will inherit those options.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
The presence of a source block in a Gemfile also makes that source
|
2018-11-02 19:07:56 -04:00
|
|
|
available as a possible global source for any other gems which do not
|
|
|
|
specify explicit sources. Thus, when defining source blocks, it is rec-
|
|
|
|
ommended that you also ensure all other gems in the Gemfile are using
|
2019-04-14 02:01:35 -04:00
|
|
|
explicit sources, either via source blocks or :source directives on
|
|
|
|
individual gems.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
INSTALL_IF
|
|
|
|
The install_if method allows gems to be installed based on a proc or
|
2018-11-02 19:07:56 -04:00
|
|
|
lambda. This is especially useful for optional gems that can only be
|
|
|
|
used if certain software is installed or some other conditions are met.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
install_if -> { RUBY_PLATFORM =~ /darwin/ } do
|
|
|
|
gem "pasteboard"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
GEMSPEC
|
2019-09-18 02:28:08 -04:00
|
|
|
The .gemspec http://guides.rubygems.org/specification-reference/ file
|
2018-11-02 19:07:56 -04:00
|
|
|
is where you provide metadata about your gem to Rubygems. Some required
|
2019-09-18 02:28:08 -04:00
|
|
|
Gemspec attributes include the name, description, and homepage of your
|
|
|
|
gem. This is also where you specify the dependencies your gem needs to
|
2018-11-02 19:07:56 -04:00
|
|
|
run.
|
|
|
|
|
|
|
|
If you wish to use Bundler to help install dependencies for a gem while
|
2019-09-18 02:28:08 -04:00
|
|
|
it is being developed, use the gemspec method to pull in the dependen-
|
2019-04-14 02:01:35 -04:00
|
|
|
cies listed in the .gemspec file.
|
|
|
|
|
|
|
|
The gemspec method adds any runtime dependencies as gem requirements in
|
2019-09-18 02:28:08 -04:00
|
|
|
the default group. It also adds development dependencies as gem
|
|
|
|
requirements in the development group. Finally, it adds a gem require-
|
2019-04-14 02:01:35 -04:00
|
|
|
ment on your project (:path => '.'). In conjunction with Bundler.setup,
|
|
|
|
this allows you to require project files in your test code as you would
|
2019-09-18 02:28:08 -04:00
|
|
|
if the project were installed as a gem; you need not manipulate the
|
2019-04-14 02:01:35 -04:00
|
|
|
load path manually or require project files via relative paths.
|
|
|
|
|
|
|
|
The gemspec method supports optional :path, :glob, :name, and :develop-
|
|
|
|
ment_group options, which control where bundler looks for the .gemspec,
|
2019-09-18 02:28:08 -04:00
|
|
|
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
|
2018-11-02 19:07:56 -04:00
|
|
|
which group development dependencies are included in.
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
When a gemspec dependency encounters version conflicts during resolu-
|
|
|
|
tion, the local version under development will always be selected --
|
|
|
|
even if there are remote versions that better match other requirements
|
2019-04-14 02:01:35 -04:00
|
|
|
for the gemspec gem.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
SOURCE PRIORITY
|
2019-09-18 02:28:08 -04:00
|
|
|
When attempting to locate a gem to satisfy a gem requirement, bundler
|
2018-11-02 19:07:56 -04:00
|
|
|
uses the following priority order:
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
1. The source explicitly attached to the gem (using :source, :path, or
|
|
|
|
:git)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
2. For implicit gems (dependencies of explicit gems), any source, git,
|
2019-09-18 02:28:08 -04:00
|
|
|
or path repository declared on the parent. This results in bundler
|
|
|
|
prioritizing the ActiveSupport gem from the Rails git repository
|
2019-04-14 02:01:35 -04:00
|
|
|
over ones from rubygems.org
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
3. The sources specified via global source lines, searching each
|
2019-04-14 02:01:35 -04:00
|
|
|
source in your Gemfile from last added to first added.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
September 2019 GEMFILE(5)
|