Ruby on Rails Gemfiles


To start, gemfiles require at least one source, in the form of the URL for a RubyGems server.

Generate a Gemfile with the default source by running bundle init. Use https so your connection to the server will be verified with SSL.

source ''

Next, declare the gems that you need, including version numbers.

gem 'rails', '4.2.6'
gem 'rack',  '>=1.1'
gem 'puma',  '~>3.0'

Most of the version specifiers, like >= 1.0, are self-explanatory. The specifier ~> has a special meaning. ~> 2.0.3 is identical to >= 2.0.3 and < 2.1. ~> 2.1 is identical to >= 2.1 and < 3.0. ~> 2.2.beta will match prerelease versions like 2.2.beta.12.

Git repositories are also valid gem sources, as long as the repo contains one or more valid gems. Specify what to check out with :tag, :branch, or :ref. The default is the master branch.

gem 'nokogiri', :git => '', :branch => 'master'

If you would like to use an unpacked gem directly from the filesystem, simply set the :path option to the path containing the gem's files.

gem 'extracted_library', :path => './vendor/extracted_library'

Dependencies can be placed into groups. Groups can be ignored at install-time (using --without) or required all at once (using Bundler.require).

gem 'rails_12factor', group: :production

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'dotenv-rails'

You can specify the required version of Ruby in the Gemfile with ruby. If the Gemfile is loaded on a different Ruby version, Bundler will raise an exception with an explanation.

ruby '2.3.1'