Skip to content

Instantly share code, notes, and snippets.

@jendiamond
Last active December 21, 2015 01:18
Show Gist options
  • Save jendiamond/6226230 to your computer and use it in GitHub Desktop.
Save jendiamond/6226230 to your computer and use it in GitHub Desktop.
Bundler - index page

What is Bundler?

Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.

Bundler's Purpose and Rationale

We designed bundler to make it easy to share your code across a number of development, staging and production machines. Of course, you know how to share your own application or gem: stick it on GitHub and clone it where you need it. Bundler makes it easy to make sure that your application has the dependencies it needs to start up and run without errors.

First, you declare these dependencies in a file at the root of your application, called Gemfile. It looks something like this:

source 'https://rubygems.org'

gem 'rails', '3.0.0.rc' gem 'rack-cache' gem 'nokogiri', '~> 1.4.2' This Gemfile says a few things. First, it says that bundler should look for gems declared in the Gemfile at http://rubygems.org. You can declare multiple Rubygems sources, and bundler will look for gems in the order you declared the sources.

Next, you declare a few dependencies:

on version 3.0.0.rc of rails on any version of rack-cache on a version of nokogiri that is >= 1.4.2 but < 1.5.0 After declaring your first set of dependencies, you tell bundler to go get them:

$ bundle install    # bundle is a shortcut for bundle install

Bundler will connect to rubygems.org (and any other sources that you declared), and find a list of all of the required gems that meet the requirements you specified. Because all of the gems in your Gemfile have dependencies of their own (and some of those have their own dependencies), running bundle install on the Gemfile above will install quite a few gems.

$ bundle install

Fetching source index for http://gemcutter.org/ Using rake (0.8.7) Using abstract (1.0.0) Installing activesupport (3.0.0.rc) Using builder (2.1.2) Using i18n (0.4.1) Installing activemodel (3.0.0.rc) Using erubis (2.6.6) Using rack (1.2.1) Installing rack-mount (0.6.9) Using rack-test (0.5.4) Using tzinfo (0.3.22) Installing actionpack (3.0.0.rc) Using mime-types (1.16) Using polyglot (0.3.1) Using treetop (1.4.8) Using mail (2.2.5) Installing actionmailer (3.0.0.rc) Using arel (0.4.0) Installing activerecord (3.0.0.rc) Installing activeresource (3.0.0.rc) Using bundler (1.0.0.rc.3) Installing nokogiri (1.4.3.1) with native extensions Installing rack-cache (0.5.2) Installing thor (0.14.0) Installing railties (3.0.0.rc) Installing rails (3.0.0.rc) Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed. If any of the needed gems are already installed, Bundler will use them. After installing any needed gems to your system, bundler writes a snapshot of all of the gems and versions that it installed to Gemfile.lock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment