gemfile.5 - bundler-1.9.9 Documentation

." generated with Ronn/v0.7.3 ." github.com/rtomayko/ronn/tree/0.7.3 . .TH “GEMFILE” “5” “May 2015” “” “” . .SH “NAME” fBGemfilefR - A format for describing gem dependencies for Ruby programs . .SH “SYNOPSIS” A fBGemfilefR describes the gem dependencies required to execute associated Ruby code. . .P Place the fBGemfilefR in the root of the directory containing the associated code. For instance, in a Rails application, place the fBGemfilefR in the same directory as the fBRakefilefR. . .SH “SYNTAX” A fBGemfilefR is evaluated as Ruby code, in a context which makes available a number of methods used to describe the gem requirements. . .SH “GLOBAL SOURCES (#source)” At the top of the fBGemfilefR, add a line for the fBRubygemsfR source that contains the gems listed in the fBGemfilefR. . .IP “” 4 . .nf

source “rubygems.org” . .fi . .IP “” 0 . .P It is possible, but not recommended as of Bundler 1.7, to add multiple global fBsourcefR lines. Each of these fBsourcefRs fBMUSTfR be a valid Rubygems repository. . .P Sources are checked for gems following the heuristics described in fISOURCE PRIORITYfR. If a gem is found in more than one global source, Bundler will print a warning after installing the gem indicating which source was used, and listing the other sources where the gem is available. A specific source can be selected for gems that need to use a non-standard repository, suppressing this warning, by using the fIfB:sourcefR optionfR or a fIfBsourcefR blockfR. . .SS “CREDENTIALS (#credentials)” Some gem sources require a username and password. Use fBbundle configfR to set the username and password for any 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. . .IP “” 4 . .nf

bundle config gems.example.com user:password . .fi . .IP “” 0 . .P For some sources, like a company Gemfury account, it may be easier to simply include the credentials in the Gemfile as part of the source URL. . .IP “” 4 . .nf

source “user:password@gems.example.com” . .fi . .IP “” 0 . .P Credentials in the source URL will take precedence over credentials set using fBconfigfR. . .SH “RUBY (#ruby)” If your application requires a specific Ruby version or engine, specify your requirements using the fBrubyfR method, with the following arguments. All parameters are fBOPTIONALfR unless otherwise specified. . .SS “VERSION (required)” The version of Ruby that your application requires. If your application requires an alternate Ruby engine, such as JRuby or Rubinius, this should be the Ruby version that the engine is compatible with. . .IP “” 4 . .nf

ruby “1.9.3” . .fi . .IP “” 0 . .SS “ENGINE (:engine)” Each application fImayfR specify a Ruby engine. If an engine is specified, an engine version fImustfR also be specified. . .SS “ENGINE VERSION (:engine_version)” Each application fImayfR specify a Ruby engine version. If an engine version is specified, an engine fImustfR also be specified. If the engine is “ruby” the engine version specified fImustfR match the Ruby version. . .IP “” 4 . .nf

ruby “1.8.7”, :engine => “jruby”, :engine_version => “1.6.7” . .fi . .IP “” 0 . .SS “PATCHLEVEL (:patchlevel)” Each application fImayfR specify a Ruby patchlevel. . .IP “” 4 . .nf

ruby “2.0.0”, :patchlevel => “247” . .fi . .IP “” 0 . .SH “GEMS (#gem)” Specify gem requirements using the fBgemfR method, with the following arguments. All parameters are fBOPTIONALfR unless otherwise specified. . .SS “NAME (required)” For each gem requirement, list a single fIgemfR line. . .IP “” 4 . .nf

gem “nokogiri” . .fi . .IP “” 0 . .SS “VERSION” Each fIgemfR fBMAYfR have one or more version specifiers. . .IP “” 4 . .nf

gem “nokogiri”, “>= 1.4.2” gem “RedCloth”, “>= 4.1.0”, “< 4.2.0” . .fi . .IP “” 0 . .SS “REQUIRE AS (:require)” Each fIgemfR fBMAYfR specify files that should be used when autorequiring via fBBundler.requirefR. You may pass an array with multiple files or fBtruefR if file you want fBrequiredfR has same name as fIgemfR or fBfalsefR to prevent any file from being autorequired. . .IP “” 4 . .nf

gem “redis”, :require => [“redis/connection/hiredis”, “redis”] gem “webmock”, :require => false gem “debugger”, :require => true . .fi . .IP “” 0 . .P The argument defaults to the name of the gem. For example, these are identical: . .IP “” 4 . .nf

gem “nokogiri” gem “nokogiri”, :require => “nokogiri” gem “nokogiri”, :require => true . .fi . .IP “” 0 . .SS “GROUPS (:group or :groups)” Each fIgemfR fBMAYfR specify membership in one or more groups. Any fIgemfR that does not specify membership in any group is placed in the fBdefaultfR group. . .IP “” 4 . .nf

gem “rspec”, :group => :test gem “wirble”, :groups => [:development, :test] . .fi . .IP “” 0 . .P The Bundler runtime allows its two main methods, fBBundler.setupfR and fBBundler.requirefR, to limit their impact to particular groups. . .IP “” 4 . .nf

# 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 just the default group Bundler.require(:default) # identical Bundler.require(:default, :test) # requires the default and test groups Bundler.require(:test) # requires just the test group . .fi . .IP “” 0 . .P The Bundler CLI allows you to specify a list of groups whose gems fBbundle installfR should not install with the fB--withoutfR option. To specify multiple groups to ignore, specify a list of groups separated by spaces. . .IP “” 4 . .nf

bundle install --without test bundle install --without development test . .fi . .IP “” 0 . .P After running fBbundle install --without testfR, bundler will remember that you excluded the test group in the last installation. The next time you run fBbundle installfR, without any fB--without optionfR, bundler will recall it. . .P Also, calling fBBundler.setupfR with no parameters, or calling fBrequire “bundler/setup”fR will setup all groups except for the ones you excluded via fB--withoutfR (since they are obviously not available). . .P Note that on fBbundle installfR, 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 versions of the same gems in different groups. For more details, see Understanding Bundler fIbundler.io/rationale.htmlfR. . .SS “PLATFORMS (:platforms)” If a gem should only be used in a particular platform or set of platforms, you can specify them. Platforms are essentially identical to groups, except that you do not need to use the fB--withoutfR install-time flag to exclude groups of gems for other platforms. . .P There are a number of fBGemfilefR platforms: . .TP fBrubyfR C Ruby (MRI) or Rubinius, but fBNOTfR Windows . .TP fBruby_18fR fIrubyfR fBANDfR version 1.8 . .TP fBruby_19fR fIrubyfR fBANDfR version 1.9 . .TP fBruby_20fR fIrubyfR fBANDfR version 2.0 . .TP fBruby_21fR fIrubyfR fBANDfR version 2.1 . .TP fBruby_22fR fIrubyfR fBANDfR version 2.2 . .TP fBmrifR Same as fIrubyfR, but not Rubinius . .TP fBmri_18fR fImrifR fBANDfR version 1.8 . .TP fBmri_19fR fImrifR fBANDfR version 1.9 . .TP fBmri_20fR fImrifR fBANDfR version 2.0 . .TP fBmri_21fR fImrifR fBANDfR version 2.1 . .TP fBmri_22fR fImrifR fBANDfR version 2.2 . .TP fBrbxfR Same as fIrubyfR, but only Rubinius (not MRI) . .TP fBjrubyfR JRuby . .TP fBmswinfR Windows . .TP fBmingwfR Windows 32 bit 'mingw32' platform (aka RubyInstaller) . .TP fBmingw_18fR fImingwfR fBANDfR version 1.8 . .TP fBmingw_19fR fImingwfR fBANDfR version 1.9 . .TP fBmingw_20fR fImingwfR fBANDfR version 2.0 . .TP fBmingw_21fR fImingwfR fBANDfR version 2.1 . .TP fBmingw_22fR fImingwfR fBANDfR version 2.2 . .TP fBx64_mingwfR Windows 64 bit 'mingw32' platform (aka RubyInstaller x64) . .TP fBx64_mingw_20fR fIx64_mingwfR fBANDfR version 2.0 . .TP fBx64_mingw_21fR fIx64_mingwfR fBANDfR version 2.1 . .TP fBx64_mingw_22fR fIx64_mingwfR fBANDfR version 2.2 . .P As with groups, you can specify one or more platforms: . .IP “” 4 . .nf

gem “weakling”, :platforms => :jruby gem “ruby-debug”, :platforms => :mri_18 gem “nokogiri”, :platforms => [:mri_18, :jruby] . .fi . .IP “” 0 . .P All operations involving groups (fBbundle installfR, fBBundler.setupfR, fBBundler.requirefR) behave exactly the same as if any groups not matching the current platform were explicitly excluded. . .SS “SOURCE (:source)” You can select an alternate Rubygems repository for a gem using the ':source' option. . .IP “” 4 . .nf

gem “some_internal_gem”, :source => “gems.example.com” . .fi . .IP “” 0 . .P 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. . .P 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 fISOURCE PRIORITYfR. . .P Selecting a specific source repository this way also suppresses the ambiguous gem warning described above in fIGLOBAL SOURCES (#source)fR. . .SS “GIT (:git)” If necessary, you can specify that a gem is located at a particular git repository using the fB:gitfR parameter. The repository can be accessed via several protocols: . .TP fBHTTP(S)fR gem “rails”, :git => “github.com/rails/rails.git” . .TP fBSSHfR gem “rails”, :git => “git@github.com:rails/rails.git” . .TP fBgitfR gem “rails”, :git => “git://github.com/rails/rails.git” . .P If using SSH, the user that you use to run fBbundle installfR fBMUSTfR have the appropriate keys available in their fB$HOME/.sshfR. . .P fBNOTEfR: fBfR and fBgit://fR 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 are strongly preferred. . .P The fBgroupfR, fBplatformsfR, and fBrequirefR options are available and behave exactly the same as they would for a normal gem. . .P A git repository fBSHOULDfR have at least one file, at the root of the directory containing the gem, with the extension fB.gemspecfR. This file fBMUSTfR contain a valid gem specification, as expected by the fBgem buildfR command. . .P If a git repository does not have a fB.gemspecfR, bundler will attempt to create one, but it will not contain any dependencies, executables, or C extension compilation instructions. As a result, it may fail to properly integrate into your application. . .P If a git repository does have a fB.gemspecfR for the gem you attached it to, a version specifier, if provided, means that the git repository is only valid if the fB.gemspecfR specifies a version matching the version specifier. If not, bundler will print a warning. . .IP “” 4 . .nf

gem “rails”, “2.3.8”, :git => “github.com/rails/rails.git” # bundle install will fail, because the .gemspec in the rails # repository's master branch specifies version 3.0.0 . .fi . .IP “” 0 . .P If a git repository does fBnotfR have a fB.gemspecfR for the gem you attached it to, a version specifier fBMUSTfR be provided. Bundler will use this version in the simple fB.gemspecfR it creates. . .P Git repositories support a number of additional options. . .TP fBbranchfR, fBtagfR, and fBreffR You fBMUSTfR only specify at most one of these options. The default is fB:branch => “master”fR . .TP fBsubmodulesfR Specify fB:submodules => truefR to cause bundler to expand any submodules included in the git repository . .P If a git repository contains multiple fB.gemspecsfR, each fB.gemspecfR represents a gem located at the same place in the file system as the fB.gemspecfR. . .IP “” 4 . .nf

|~rails [git root] | |-rails.gemspec [rails gem located here] |~actionpack | |-actionpack.gemspec [actionpack gem located here] |~activesupport | |-activesupport.gemspec [activesupport gem located here] |... . .fi . .IP “” 0 . .P To install a gem located in a git repository, bundler changes to the directory containing the gemspec, runs fBgem build name.gemspecfR and then installs the resulting gem. The fBgem buildfR command, which comes standard with Rubygems, evaluates the fB.gemspecfR in the context of the directory in which it is located. . .SS “GIT SOURCE (:git_source)” A custom git source can be defined via the fBgit_sourcefR 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: . .IP “” 4 . .nf

git_source(:stash){ |repo_name| “stash.corp.acme.pl/#{repo_name}.git” } gem 'rails', :stash => 'forks/rails' . .fi . .IP “” 0 . .P In addition, if you wish to choose a specific branch: . .IP “” 4 . .nf

gem “rails”, :stash => “forks/rails”, :branch => “branch_name” . .fi . .IP “” 0 . .SS “GITHUB (:github)” fBNOTEfR: This shorthand should be avoided until Bundler 2.0, since it currently expands to an insecure fBgit://fR URL. This allows a man-in-the-middle attacker to compromise your system. . .P If the git repository you want to use is hosted on GitHub and is public, you can use the :github shorthand to specify just 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. . .IP “” 4 . .nf

gem “rails”, :github => “rails/rails” gem “rails”, :github => “rails” . .fi . .IP “” 0 . .P Are both equivalent to . .IP “” 4 . .nf

gem “rails”, :git => “git://github.com/rails/rails.git” . .fi . .IP “” 0 . .P Since the fBgithubfR method is a specialization of fBgit_sourcefR, it accepts a fB:branchfR named argument. . .SS “GIST (:gist)” If the git repository you want to use is hosted as a Github Gist and is public, you can use the :gist shorthand to specify just the gist identifier (without the trailing “.git”). . .IP “” 4 . .nf

gem “the_hatch”, :gist => “4815162342” . .fi . .IP “” 0 . .P Is equivalent to: . .IP “” 4 . .nf

gem “the_hatch”, :git => “gist.github.com/4815162342.git” . .fi . .IP “” 0 . .P Since the fBgistfR method is a specialization of fBgit_sourcefR, it accepts a fB:branchfR named argument. . .SS “BITBUCKET (:bitbucket)” If the git repository you want to use is hosted on Bitbucket and is public, you can use the :bitbucket shorthand to specify just 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. . .IP “” 4 . .nf

gem “rails”, :bitbucket => “rails/rails” gem “rails”, :bitbucket => “rails” . .fi . .IP “” 0 . .P Are both equivalent to . .IP “” 4 . .nf

gem “rails”, :git => “rails@bitbucket.org/rails/rails.git” . .fi . .IP “” 0 . .P Since the fBbitbucketfR method is a specialization of fBgit_sourcefR, it accepts a fB:branchfR named argument. . .SS “PATH (: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 containing the fBGemfilefR. . .P Similar to the semantics of the fB:gitfR option, the fB:pathfR option requires that the directory in question either contains a fB.gemspecfR for the gem, or that you specify an explicit version that bundler should use. . .P Unlike fB:gitfR, bundler does not compile C extensions for gems specified as paths. . .IP “” 4 . .nf

gem “rails”, :path => “vendor/rails” . .fi . .IP “” 0 . .P If you would like to use multiple local gems directly from the filesystem, you can set a global fBpathfR option to the path containing the gem's files. This will automatically load gemspec files from subdirectories. . .IP “” 4 . .nf

path 'components' do

    gem \'admin_ui\'
    gem \'public_ui\'

end . .fi . .IP “” 0 . .SH “BLOCK FORM OF SOURCE, GIT, PATH, GROUP and PLATFORMS” The fB:sourcefR, fB:gitfR, fB:pathfR, fB:groupfR, and fB:platformsfR options may be applied to a group of gems by using block form. . .IP “” 4 . .nf

source “gems.example.com” do

    gem "some_internal_gem"
    gem "another_internal_gem"

end

git “github.com/rails/rails.git” do

    gem "activesupport"
    gem "actionpack"

end

platforms :ruby do

    gem "ruby\-debug"
    gem "sqlite3"

end

group :development do

    gem "wirble"
    gem "faker"

end . .fi . .IP “” 0 . .P In the case of the fBgitfR block form, the fB:reffR, fB:branchfR, fB:tagfR, and fB:submodulesfR options may be passed to the fBgitfR method, and all gems in the block will inherit those options. . .SH “GEMSPEC (#gemspec)” If you wish to use Bundler to help install dependencies for a gem while it is being developed, use the fBgemspecfR method to pull in the dependencies listed in the fB.gemspecfR file. . .P The fBgemspecfR method adds any runtime dependencies as gem requirements in the default group. It also adds development dependencies as gem requirements in the fBdevelopmentfR group. Finally, it adds a gem requirement on your project (fB:path => '.'fR). In conjunction with fBBundler.setupfR, this allows you to require project files in your test code as you would if the project were installed as a gem; you need not manipulate the load path manually or require project files via relative paths. . .P The fBgemspecfR method supports optional fB:pathfR, fB:namefR, and fB:development_groupfR options, which control where bundler looks for the fB.gemspecfR, what named fB.gemspecfR it uses (if more than one is present), and which group development dependencies are included in. . .SH “SOURCE PRIORITY” When attempting to locate a gem to satisfy a gem requirement, bundler uses the following priority order: . .IP “1.” 4 The source explicitly attached to the gem (using fB:sourcefR, fB:pathfR, or fB:gitfR) . .IP “2.” 4 For implicit gems (dependencies of explicit gems), any source, git, or path repository declared on the parent. This results in bundler prioritizing the ActiveSupport gem from the Rails git repository over ones from fBrubygems.orgfR . .IP “3.” 4 The sources specified via global fBsourcefR lines, searching each source in your fBGemfilefR from last added to first added. . .IP “” 0