Using a Gemfile and Bundler

suggest change

A Gemfile is the standard way to organize dependencies in your application. A basic Gemfile will look like this:

source 'https://rubygems.org'

gem 'rack'
gem 'sinatra'
gem 'uglifier'

You can specify the versions of the gems you want as follows:

# Stay within a compatible minor release.
gem 'rack', '~> 3.2'
# Use a specific version.
gem 'sinatra', '4.2.1'
# Use this version or anything greater.
gem 'uglifier', '>= 4.2.1'

You can also pull gems straight from a git repo:

# Pull a gem from GitHub.
gem 'sinatra', git: 'https://github.com/sinatra/sinatra.git'
# You can specify a revision.
gem 'sinatra', git: 'https://github.com/sinatra/sinatra.git', ref: '30d4fb4'
# You can also specify a branch, though this is less reproducible.
gem 'sinatra', git: 'https://github.com/sinatra/sinatra.git', branch: 'main'

You can also group gems depending on what they are used for. For example:

group :development, :test do
  # This gem is not installed in production.
  gem 'debug'
end

You can specify which platform certain gems should run on if your application needs to be able to run on multiple platforms. For example:

platform :jruby do
  gem 'activerecord-jdbc-adapter'
  gem 'jdbc-postgres'
end

platform :ruby do
  gem 'pg'
end

To install all the gems from a Gemfile do:

gem install bundler
bundle install

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents