How to manage groups of gems
# These gems are in the :default group gem 'nokogiri' gem 'sinatra' gem 'wirble', group: :development group :test do gem 'faker' gem 'rspec' end group :test, :development do gem 'capybara' gem 'rspec-rails' end gem 'cucumber', group: [:cucumber, :test]
$ bundle config set --local without test development
require 'rubygems' require 'bundler' Bundler.setup(:default, :ci) require 'nokogiri'
Optional groups and
group :name, optional: true doand then opt into installing an optional group with
bundle config set --local with name.
Grouping your dependencies
pg. In this example, you might not have MySQL or Postgres installed on your development machine and want bundler to skip it. To do this, you can group your dependencies:
source 'https://rubygems.org' gem 'rails', '3.2.2' gem 'rack-cache', require: 'rack/cache' gem 'nokogiri', '~> 1.4.2' group :development do gem 'sqlite3' end group :production do gem 'pg' end
$ bundle config set --local without production
APP_ROOT/.bundle/configand the next time you run `bundle install`, it will skip production gems. Similarly, when you require `bundler/setup`, Bundler will ignore gems in these groups. You can see all of the settings that Bundler saved there by running
bundle config, which will also print out global settings (stored in
~/.bundle/config) and settings set via environment variables. For more information on configuring Bundler, please see: bundle config
You can also specify which groups to automatically require through the parameters to
:default group includes all gems not
listed under any group. If you call
require all the gems in the
:default group as
well as the gems in the
By default, a Rails generated app calls
Rails.env) in your
application.rb, which links the groups in your
Gemfile to the Rails environment. If you use other groups (not linked to a
Rails environment), you can add them to the call to
Bundler.require if you
want them to be automatically required.
Remember that you can always leave groups of gems out of
and then require them manually using Ruby's
require at the appropriate
place in your app. You might do this because requiring a certain gem takes some time
and you don't need it every time you boot your application.