Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Rails Support
      • Working with Bundler
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with the Play Framework
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Ruby
  • Working with Bundler
  • Managing Gems with Bundler

Managing Gems with Bundler

English — 日本語に切り替える

Last updated March 24, 2022

Table of Contents

  • Using Bundler
  • Specifying gems and groups
  • Frameworks
  • Versions of Bundler
  • Further reading

Bundler is the default gem dependency manager for Ruby projects. Bundler is the way to manage your gems on Heroku.

Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket.

Using Bundler

To use, install bundler:

$ gem install bundler

Create a file named Gemfile in the root of your app specifying what gems are required to run it:

source "https://rubygems.org"
gem 'sinatra', '1.0'

This file should be added to the git repository since it is part of the app. You should also add the .bundle directory to your .gitignore file. Once you have added the Gemfile, it makes it easy for other developers to get their environment ready to run the app:

$ bundle install -j4

This ensures that all gems specified in Gemfile, together with their dependencies, are available for your application. Running bundle install also generates a Gemfile.lock file, which should be added to your git repository. Gemfile.lock ensures that your deployed versions of gems on Heroku match the version installed locally on your development machine. The flag -j4 will use 4 parallel jobs to install all of your dependencies. This feature was introduced in bundler 1.5.0

If the platforms section of your Gemfile contains Windows entries, such as mswin or mingw, then the Gemfile.lock file will be ignored.

Heroku also uses that file to resolve and install your application dependencies automatically. All you need to do is to push it:

-----> Heroku receiving push
-----> Sinatra app detected
-----> Gemfile detected, running Bundler version 1.5.2
       Unresolved dependencies detected; Installing...
       Using rack (1.2.1)
       Using sinatra (1.0)
       Using bundler (1.0.0)
       Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

       Your bundle was installed to `.bundle/gems`
       Compiled slug size is 10.7MB
-----> Launching.... done

Specifying gems and groups

The recommended use of gem bundler is to bundle absolutely every gem your app depends upon. This includes your framework (Rails, Sinatra, etc) and your database connectors.

Bundling Rails and other dependencies does increase your slug size by a few megabytes. Increased slug size is a worthwhile tradeoff for vastly simplified dependency management, as well as the flexibility of being able to use any version of Rails you wish.

To specify groups of gems to not to be installed, you can use the BUNDLE_WITHOUT config var.

$ heroku config:set BUNDLE_WITHOUT="development:test"

Frameworks

Using Bundler with Rails 3

Rails 3 is built on top of Bundler. That means there is no setup needed, all gems specified on the Gemfile are ready for use on your app.

Using Bundler with Rails 2.3.X

Follow the instructions here. Remember to remove all your config.gem lines from your environment configuration file! Also remember to specify the appropriate database gem for your app.

gem "pg", :group => :production
gem "sqlite3-ruby", :group => :development

After you have added the code to your application, run

$ bundle install

And your app is running with Bundler.

Using Bundler from Sinatra (or Other Rack Apps)

Gembundler has a great set of documentation on how to use Bundler with Sinatra and other frameworks as well.

Versions of Bundler

See Bundler Version about using different versions of Bundler.

Further reading

  • Bundler Docs

Keep reading

  • Working with Bundler

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences