陈斌彬的技术博客

Stay foolish,stay hungry

Ruby-Bundler 介绍

img

What is Bundler?

Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.

Bundler is an exit from dependency hell, and ensures that the gems you need are present in development, staging, and production. Starting work on a project is as simple as bundle install.

Getting Started

Getting started with bundler is easy! Open a terminal window and run this command:

$ gem install bundler

Specify your dependencies in a Gemfile in your project’s root:

source 'https://rubygems.org'
gem 'nokogiri'
gem 'rack', '~>1.1'
gem 'rspec', :require => 'spec'

Install all of the required gems from your specified sources:

$ bundle install
$ git add Gemfile Gemfile.lock

The second command adds the Gemfile and Gemfile.lock to your repository. This ensures that other developers on your app, as well as your deployment environment, will all use the same third-party code that you are using now.

Inside your app, load up the bundled environment:

require 'rubygems'
require 'bundler/setup'

# require your gems as usual
require 'nokogiri'

Run an executable that comes with a gem in your bundle:

$ bundle exec rspec spec/models

Bundler Site

http://bundler.io/