A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.
At the top of your Gemfile, include a line for the RubyGems source that contains all the gems listed in the Gemfile by using the source
method. In the vast majority of cases, the gem source
will be, https://rubygems.org.
source 'https://rubygems.org'
# Gems go here
In some instances, a gem source
will require a username and password. In these cases, use bundle config(1)
to set the credentials.
$ bundle config https://gems.example.com/ user:password
If your program requires a specific Ruby version or engine, use the ruby
method to specify your requirements.
This method requires a version argument. Other optional arguments include:
:patchlevel
– indicates Ruby’s patch level
:engine
– indicates the Ruby engine
:engine_version
– indicates the version of the engine being used. This argument cannot be used without the :engine
argument.
ruby "1.9.3", :engine => 'jruby', :engine_version => "1.6.7", :patchlevel => 247
The most basic syntax for setting up a gem is,
gem “my_gem”
where my_gem
is the name of the gem. The gem version is also commonly set. The seven operators you can use to set your gem’s version are: