Go to main content

man pages section 5: File Formats

Exit Print View

Updated: Thursday, June 13, 2019
 
 

gemfile (5)

Name

gemfile - Man page for 'gemfile' in section 5

Synopsis

Please see following description for synopsis

Description

TH "GEMFILE" "5" "November 2018" "" "" SH "NAME" Gemfile - A for-
mat for describing gem dependencies for Ruby programs SH  "SYNOP-
SIS" A Gemfile describes the gem dependencies required to execute
associated Ruby code.  P Place the Gemfile in the root of the di-
rectory  containing the associated code. For instance, in a Rails
application, place the Gemfile in the same directory as the Rake-
file.  SH "SYNTAX" A Gemfile is evaluated as Ruby code, in a con-
text which makes available a number of methods used  to  describe
the gem requirements.  SH "GLOBAL SOURCES" At the top of the Gem-
file, add a line for the Rubygems source that contains  the  gems
listed in the Gemfile.  IP "" 4 nf

source  "https://rubygems.org"  fi  IP "" 0 P It is possible, but
not recommended as of Bundler 1.7, to add multiple global  source
lines. Each of these sources MUST be a valid Rubygems repository.
P Sources are checked for gems following the heuristics described
in  SOURCE  PRIORITY.  If  a gem is found in more than one global
source, Bundler will print a warning after installing the gem in-
dicating  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 :source option or a source block.  SS "CRE-
DENTIALS"  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.  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
include the credentials in the Gemfile as part of the source URL.
IP "" 4 nf

source "https://user:password@gems.example.com" fi IP "" 0 P Cre-
dentials in the source URL will take precedence over  credentials
set  using config.  SH "RUBY" If your application requires a spe-
cific Ruby version or engine, specify your requirements using the
ruby method, with the following arguments. All parameters are OP-
TIONAL unless otherwise specified.  SS "VERSION  (required)"  The
version  of Ruby that your application requires. If your applica-
tion requires an alternate Ruby engine, such as  JRuby,  Rubinius
or  TruffleRuby,  this should be the Ruby version that the engine
is compatible with.  IP "" 4 nf

ruby "1.9.3" fi IP "" 0 SS "ENGINE" Each application may  specify
a  Ruby engine. If an engine is specified, an engine version must
also be specified.  P What exactly is an Engine? - A Ruby  engine
is  an  implementation  of the Ruby language.  IP "o" 4 For back-
ground: the reference or original implementation of the Ruby pro-
gramming    language    is   called   Matz's   Ruby   Interpreter
https://en.wikipedia.org/wiki/Ruby_MRI, or MRI for short. This is
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.  IP "o" 4 Other implementations
https://www.ruby-lang.org/en/about/ of Ruby exist.  Some  of  the
more  well-known  implementations  include  Rubinius  https://ru-
binius.com/, and JRuby http://jruby.org/. Rubinius is an alterna-
tive  implementation  of Ruby written in Ruby. JRuby is an imple-
mentation of Ruby on the JVM, short for Java Virtual Machine.  IP
""  0 SS "ENGINE VERSION" Each application may specify a Ruby en-
gine version. If an engine version is specified, an  engine  must
also  be  specified.  If  the engine is "ruby" the engine version
specified must match the Ruby version.  IP "" 4 nf

ruby "1.8.7", :engine => "jruby", :engine_version =>  "1.6.7"  fi
IP  ""  0  SS  "PATCHLEVEL"  Each  application may specify a Ruby
patchlevel.  IP "" 4 nf

ruby "2.0.0", :patchlevel => "247" fi IP "" 0 SH  "GEMS"  Specify
gem  requirements  using the gem method, with the following argu-
ments. All parameters are OPTIONAL  unless  otherwise  specified.
SS  "NAME (required)" For each gem requirement, list a single gem
line.  IP "" 4 nf

gem "nokogiri" fi IP "" 0 SS "VERSION" Each gem MAY 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" 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 autore-
quired.  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 "noko-
giri", :require => true fi IP "" 0 SS "GROUPS" Each gem MAY spec-
ify membership in one or more groups. Any gem that does not spec-
ify membership in any group is placed in the default  group.   IP
"" 4 nf

gem  "rspec", :group => :test gem "wirble", :groups => [:develop-
ment, :test] fi IP "" 0 P The Bundler runtime allows its two main
methods, Bundler.setup and Bundler.require, 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  the  _default_
group  Bundler.require(:default)         #  identical Bundler.re-
quire(:default, :test) # requires the _default_ and _test_ groups
Bundler.require(:test)            #  requires the _test_ group fi
IP "" 0 P The Bundler CLI allows you to specify a list of  groups
whose  gems  bundle install should not install with the --without
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 develop-
ment test fi IP "" 0 P 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.  P Also,
calling Bundler.setup with  no  parameters,  or  calling  require
"bundler/setup" will setup all groups except for the ones you ex-
cluded via --without (since they are not available).  P 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 dif-
ferent versions of the same gems in different  groups.  For  more
details,   see   Understanding  Bundler  http://bundler.io/ratio-
nale.html.  SS "PLATFORMS" If a gem should only be used in a par-
ticular platform or set of platforms, you can specify them. Plat-
forms 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.  P There are a number of Gemfile  plat-
forms:  TP  ruby  C  Ruby (MRI), Rubinius or TruffleRuby, but NOT
Windows TP mri Same as ruby, but only C Ruby (MRI) TP mingw  Win-
dows  32  bit 'mingw32' platform (aka RubyInstaller) TP x64_mingw
Windows 64 bit 'mingw32' platform (aka RubyInstaller x64) TP  rbx
Rubinius  TP jruby JRuby TP truffleruby TruffleRuby TP mswin Win-
dows P You can restrict further by platform and version  for  all
platforms  except  for  rbx,  jruby, truffleruby and mswin.  P To
specify a version in addition to a platform, append  the  version
number  without  the  delimiter  to the platform. For example, to
specify that a gem should only be used  on  platforms  with  Ruby
2.3, use: IP "" 4 nf

ruby_23  fi  IP  ""  0 P The full list of platforms and supported
versions includes: TP ruby 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5
TP  mri 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 TP mingw 1.8, 1.9,
2.0, 2.1, 2.2, 2.3, 2.4, 2.5 TP x64_mingw  2.0,  2.1,  2.2,  2.3,
2.4, 2.5 P As with groups, you can specify one or more platforms:
IP "" 4 nf

gem "weakling",   :platforms => :jruby gem  "ruby-debug",  :plat-
forms  => :mri_18 gem "nokogiri",   :platforms => [:mri_18, :jru-
by] fi IP "" 0 P All operations involving groups (bundle  install
bundle-install.1.html, Bundler.setup, Bundler.require) behave ex-
actly the same as if any groups not matching the current platform
were  explicitly  excluded.  SS "SOURCE" You can select an alter-
nate Rubygems repository for a gem using  the  ':source'  option.
IP "" 4 nf

gem "some_internal_gem", :source => "https://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  in-
stalled.   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 SOURCE PRIORITY.  P  Selecting  a
specific source repository this way also suppresses the ambiguous
gem warning described above in GLOBAL SOURCES (#source).  P 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.  SS "GIT"
If necessary, you can specify that a gem is located at a particu-
lar  git  repository using the :git parameter. The repository can
be accessed via several protocols: TP HTTP(S) gem  "rails",  :git
=>  "https://github.com/rails/rails.git" TP SSH gem "rails", :git
=> "git@github.com:rails/rails.git" TP git gem "rails",  :git  =>
"git://github.com/rails/rails.git"  P If using SSH, the user that
you use to run bundle install  MUST  have  the  appropriate  keys
available  in  their $HOME/.ssh.  P NOTE: http:// and git:// URLs
should be avoided if at all possible. These protocols  are  unau-
thenticated,  so  a  man-in-the-middle attacker can deliver mali-
cious code and compromise your system. HTTPS and SSH are strongly
preferred.   P  The  group,  platforms,  and  require options are
available and behave exactly the same as they would for a  normal
gem.   P  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.  P If a  git  repository  does
not  have  a .gemspec, 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  .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.  IP "" 4 nf

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 fi IP "" 0 P If a git repository does not
have a .gemspec for the gem you attached it to, a version  speci-
fier  MUST be provided. Bundler will use this version in the sim-
ple .gemspec it creates.  P Git repositories support a number  of
additional options.  TP branch, tag, and ref You MUST only speci-
fy at most one of these options. The default is :branch =>  "mas-
ter" TP For example: IP git "https://github.com/rails/rails.git",
:branch       =>       "5-0-stable"       do        IP        git
"https://github.com/rails/rails.git",  :tag => "v5.0.0" do IP git
"https://github.com/rails/rails.git", :ref => "4aded" do TP  sub-
modules       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 repository.
Specify :submodules => true to cause bundler to expand  any  sub-
modules included in the git repository P If a git repository con-
tains multiple .gemspecs, each .gemspec represents a gem  located
at the same place in the file system as the .gemspec.  IP "" 4 nf

|~rails                      [git    root]    |   |-rails.gemspec
[rails gem  located  here]  |~actionpack  |  |-actionpack.gemspec
[actionpack  gem  located  here]  |~activesupport  | |-activesup-
port.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 gem build name.gemspec
and then installs the resulting gem. The gem build command, which
comes standard with Rubygems, evaluates the .gemspec in the  con-
text  of the directory in which it is located.  SS "GIT SOURCE" A
custom git source can be defined via the git_source method.  Pro-
vide 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| "https://stash.corp.acme.pl/#{re-
po_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" NOTE: This shorthand should be avoided  until
Bundler  2.0,  since  it  currently expands to an insecure git://
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 speci-
fy  the github username and repository name (without the trailing
".git"), separated by a slash. If both the username and reposito-
ry 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 github method is a specialization of git_source, it
accepts a :branch named argument.  SS "GIST" If the git reposito-
ry  you want to use is hosted as a Github Gist and is public, you
can use the :gist shorthand to specify the gist identifier (with-
out 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 => "https://gist.github.com/4815162342.git"
fi  IP  ""  0  P  Since  the  gist  method is a specialization of
git_source, it accepts a :branch named argument.  SS  "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 reposito-
ry 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      =>       "https://rails@bitbuck-
et.org/rails/rails.git"  fi  IP "" 0 P Since the bitbucket method
is a specialization of git_source, it accepts a :branch named ar-
gument.   SS  "PATH"  You  can specify that a gem is located in a
particular location on the file system. Relative  paths  are  re-
solved relative to the directory containing the Gemfile.  P Simi-
lar to the semantics of the :git option,  the  :path  option  re-
quires  that the directory in question either contains a .gemspec
for the gem, or that you specify an explicit version that bundler
should use.  P Unlike :git, 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 path option to the  path  containing  the  gem's
files.  This will automatically load gemspec files from subdirec-
tories.  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 :source, :git, :path, :group, and
:platforms options may be applied to a group  of  gems  by  using
block form.  IP "" 4 nf

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  fi  IP "" 0 P 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.  P In the case of the git block form, the
:ref, :branch, :tag, and :submodules options may be passed to the
git method, and all gems in the block will inherit those options.
P  The  presence  of  a source block in a Gemfile also makes that
source available as a possible global source for any  other  gems
which do not specify explicit sources. Thus, when defining source
blocks, it is recommended that you also ensure all other gems  in
the  Gemfile are using explicit sources, either via source blocks
or :source directives on individual gems.   SH  "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.  IP "" 4 nf

install_if -> { RUBY_PLATFORM =~ /darwin/ } do
  gem "pasteboard" end fi IP  ""  0  SH  "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.  P If you wish to use Bundler to help install
dependencies for a gem while it is being developed, use the  gem-
spec  method  to  pull in the dependencies listed in the .gemspec
file.  P The gemspec method adds any runtime dependencies as  gem
requirements  in  the default group. It also adds development de-
pendencies as gem requirements in the development group. Finally,
it adds a gem requirement on your project (:path => '.'). In con-
junction with Bundler.setup, this allows you to  require  project
files  in  your  test  code  as you would if the project were in-
stalled as a gem; you need not manipulate the load path  manually
or  require  project  files  via  relative  paths.  P 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:
"{,,/*}.gemspec"),  what named .gemspec it uses (if more than one
is present), and which group development dependencies are includ-
ed  in.  P When a gemspec dependency encounters version conflicts
during resolution, the local version under development  will  al-
ways be selected -- even if there are remote versions that better
match other requirements for the gemspec gem.  SH "SOURCE PRIORI-
TY" 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 :source, :path, or :git) IP
"2." 4 For implicit gems (dependencies  of  explicit  gems),  any
source,  git, or path repository declared on the parent. This re-
sults in bundler prioritizing  the  ActiveSupport  gem  from  the
Rails  git  repository  over ones from rubygems.org IP "3." 4 The
sources specified via global source lines, searching each  source
in your Gemfile from last added to first added.  IP "" 0



See for descriptions of the following attributes:

+---------------+------------------+
|ATTRIBUTE TYPE | ATTRIBUTE VALUE  |
+---------------+------------------+
|Availability   | runtime/ruby-26  |
+---------------+------------------+
|Stability      | Uncommitted      |
+---------------+------------------+

This    software    was    built   from   source   available   at
https://github.com/oracle/solaris-userland.  The original  commu-
nity    source    was    downloaded    from    http://cache.ruby-
lang.org/pub/ruby/2.6/ruby-2.6.0.tar.gz

Further information about this software can be found on the  open
source community website at http://www.ruby-lang.org/.