Read the manual for an in-depth discussion of all of the options available in theGemfile manual
Gemfileand how to use them.
Gemfiles require at least one gem source, in the form of the URL for a RubyGems server. There are shortcuts for the default gem server, so all of these sources are the same.
source :rubygems source 'https://rubygems.org' source :rubyforge source 'http://gems.rubyforge.org' source :gemcutter source 'http://gemcutter.org'
Declare the gems that you need, including version numbers. Specify versions using the same syntax that RubyGems supports for dependencies.
gem 'nokogiri' gem 'rails', '3.0.0.beta3' gem 'rack', '>=1.0' gem 'thin', '~>1.1'
Most of the version specifiers, likeRubyGems version specifiers
>= 1.0, are self-explanatory. The specifier
~>has a special meaning, best shown by example.
~> 2.0.3is identical to
~> 2.1is identical to
~> 2.2.betawill match prerelease versions like
If a gem's main file is different than the gem name, specify how to require it.
gem 'rspec', :require => 'spec' gem 'sqlite3'
:require => falseto prevent bundler from requiring the gem, but still install it and maintain dependencies.
gem 'rspec', :require => false gem 'sqlite3'
In order to require gems in yourLearn More: Bundler.require
Gemfile, you will need to call
Bundler.requirein your application.
Git repositories are also valid gem sources, as long as the repo contains one or more valid gems. Specify what to check out with
:ref. The default is the
gem 'nokogiri', :git => 'https://github.com/tenderlove/nokogiri.git', :branch => '1.4' git 'https://github.com/wycats/thor.git', :tag => 'v0.13.4' gem 'thor'
If the git repository does not contain aLearn More: Git
.gemspecfile, bundler will create a simple one, without any dependencies, executables or C extensions. This may work for simple gems, but not work for others. If there is no .gemspec, you probably shouldn't use the gem from git.
If you are actively developing a gem, perhaps checked out from Github, you can use the gem directly from its directory on your filesystem.
gem 'nokogiri', :path => '~/sw/gems/nokogiri'
Dependencies can be placed into groups, to be ignored at install-time or required all at once.
Learn More: Groups
gem 'wirble', :group => :development gem 'ruby-debug', :group => [:development, :test] group :test do gem 'rspec' end
You can now specify the version of Ruby in the
Gemfilelike the following:
What this means is that this app has a dependency to a Ruby VM that is ABI compatible with 1.9.3. If the version check does not match, Bundler will raise an exception. This will ensure the running code matches. You can be more specific with the
Learn More: Ruby Directive
ruby '1.9.3', :engine => 'jruby', :engine_version => '1.6.7'