Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile.
source "https://rubygems.org"
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.
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 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 :source option or a source block.
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.
Credentials in the source URL will take precedence over credentials set using config.
ruby "1.9.3"
What exactly is an Engine? - A Ruby engine is an implementation of the Ruby language.
ruby "1.8.7", :engine => "jruby", :engine_version => "1.6.7"
ruby "2.0.0", :patchlevel => "247"
gem "nokogiri"
gem "nokogiri", ">= 1.4.2" gem "RedCloth", ">= 4.1.0", "< 4.2.0"
gem "redis", :require => ["redis/connection/hiredis", "redis"] gem "webmock", :require => false gem "byebug", :require => true
The argument defaults to the name of the gem. For example, these are identical:
gem "nokogiri" gem "nokogiri", :require => "nokogiri" gem "nokogiri", :require => true
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.
# 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
The Bundler CLI allows you to specify a list of groups whose gems bundle install should not install with the without configuration.
To specify multiple groups to ignore, specify a list of groups separated by spaces.
bundle config set --local without test bundle config set --local without development test
Also, calling Bundler.setup with no parameters, or calling require "bundler/setup" will setup all groups except for the ones you excluded via --without (since they are not available).
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 versions of the same gems in different groups. For more details, see Understanding Bundler https://bundler.io/rationale.html.
There are a number of Gemfile platforms:
You can restrict further by platform and version for all platforms except for rbx, jruby, truffleruby and mswin.
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:
ruby_23
The full list of platforms and supported versions includes:
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]
All operations involving groups (bundle install bundle-install.1.html, Bundler.setup, Bundler.require) behave exactly the same as if any groups not matching the current platform were explicitly excluded.
gem "some_internal_gem", :source => "https://gems.example.com"
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.
Selecting a specific source repository this way also suppresses the ambiguous gem warning described above in GLOBAL SOURCES (#source).
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.
If using SSH, the user that you use to run bundle install MUST have the appropriate keys available in their $HOME/.ssh.
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 are strongly preferred.
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 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.
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.
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
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 version in the simple .gemspec it creates.
Git repositories support a number of additional options.
If a git repository contains multiple .gemspecs, each .gemspec represents a gem located at the same place in the file system as the .gemspec.
|~rails [git root] | |-rails.gemspec [rails gem located here] |~actionpack | |-actionpack.gemspec [actionpack gem located here] |~activesupport | |-activesupport.gemspec [activesupport gem located here] |...
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 context of the directory in which it is located.
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"
If the git repository you want to use is hosted on GitHub and is public, 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.
gem "rails", :github => "rails/rails" gem "rails", :github => "rails"
Are both equivalent to
gem "rails", :git => "git://github.com/rails/rails.git"
Since the github method is a specialization of git_source, it accepts a :branch named argument.
gem "the_hatch", :gist => "4815162342"
Is equivalent to:
gem "the_hatch", :git => "https://gist.github.com/4815162342.git"
Since the gist method is a specialization of git_source, it accepts a :branch named argument.
gem "rails", :bitbucket => "rails/rails" gem "rails", :bitbucket => "rails"
Are both equivalent to
gem "rails", :git => "https://rails@bitbucket.org/rails/rails.git"
Since the bitbucket method is a specialization of git_source, it accepts a :branch named argument.
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 filesystem, 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 group :development, :optional => true do gem "wirble" gem "faker" 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 :submodules options may be passed to the git method, and all gems in the block will inherit those options.
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.
install_if -> { RUBY_PLATFORM =~ /darwin/ } do gem "pasteboard" end
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 dependencies listed in the .gemspec file.
The gemspec method adds any runtime dependencies as gem requirements in the default group. It also adds development dependencies as gem requirements in the development group. Finally, it adds a gem requirement on your project (:path => '.'). In conjunction with Bundler.setup, 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.
The gemspec method supports optional :path, :glob, :name, and :development_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 included in.
When a gemspec dependency encounters version conflicts during resolution, the local version under development will always be selected -- even if there are remote versions that better match other requirements for the gemspec gem.