Getting Started
Guides
Dependency Management
- How to manage application dependencies with Bundler
- How to manage dependencies with Bundler
- How to update gems with Bundler
- How to manage groups of gems
- How to install gems from git repositories
- Recommended Workflow with Version Control
- How to use Bundler with Ruby
- How to use Bundler in a single-file Ruby script
- How to deploy bundled applications
Gem Development
Publishing & Security
- Trusted Publishing
- Setting up multi-factor authentication
- Using multi-factor authentication in command line
- MFA requirement opt in
- Managing owners using UI
- Organizations
- Removing a Published gem
- Security Practices
Integrations
- How to use Bundler with Rails
- How to use Bundler with Sinatra
- How to use Bundler with Docker
- How to use Bundler with RubyMotion
Hosting & Sources
Extending
Troubleshooting
- How to troubleshoot RubyGems and Bundler TLS/SSL Issues
- SSL Certificate Update
- How to use git bisect with Bundler
Concepts
Reference
- gem Command Reference
- Bundler Command Reference
- Gemfile Reference
- Ruby Directive
- Specification Reference
- RubyGems.org API
- RubyGems.org API V2.0
- RubyGems.org Compact Index API
- RubyGems.org rate limits
- API key scopes
- Bundler compatibility with Ruby
- Known Bundler Plugins
Appendix
How to use Bundler with Ruby
Configure the load path so all dependencies in your Gemfile can be required
require 'bundler/setup'
require 'nokogiri'
Only add gems from specified groups to the load path. If you want the gems in the default group, make sure to include it
require 'bundler'
Bundler.setup(:default, :ci)
require 'nokogiri'
Compatibility
Ruby 2.0 and RubyGems 2.0 both require Bundler 1.3 or later. If you have questions about compatibility between Bundler and your system, please check the compatibility list.
Setting Up Your Application to Use Bundler
Bundler makes sure that Ruby can find all of the gems in the Gemfile
(and all of their dependencies). If your app is a Rails app, your default application
already has the code necessary to invoke bundler.
For another kind of application (such as a Sinatra application), you will need to set up
bundler before trying to require any gems. At the top of the first file that your
application loads (for Sinatra, the file that calls require 'sinatra'), put
the following code:
require 'bundler/setup'
This will automatically discover your Gemfile and make all of the gems in
your Gemfile available to Ruby (in technical terms, it puts the gems “on the
load path”).
Now that your code is available to Ruby, you can require the gems that you need. For
instance, you can require 'sinatra'. If you have a lot of dependencies, you
might want to say “require all of the gems in my Gemfile”. To do this, put
the following code immediately following require 'bundler/setup':
Bundler.require(:default)
For our example Gemfile, this line is exactly equivalent to:
require 'rails'
require 'rack-cache'
require 'nokogiri'
Astute readers will notice that the correct way to require the rack-cache
gem is require 'rack/cache', not require 'rack-cache'. To tell
bundler to use require 'rack/cache', update your Gemfile:
source 'https://rubygems.org'
gem 'rails', '5.0.0'
gem 'rack-cache', require: 'rack/cache'
gem 'nokogiri', '~> 1.4.2'
For such a small Gemfile, we’d advise you to skip
Bundler.require and just require the gems by hand (especially given the
need to put in a :require directive in the Gemfile). For much
larger Gemfiles, using Bundler.require allows you to skip
repeating a large stack of requirements.