Elastic Beanstalk
Ruby on Rails
Git Installation
Bundler
AWS Deployment

Elastic Beanstalk Ruby/Rails need to install git so bundle install works.. but is not

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

If bundle install fails on Elastic Beanstalk because a gem comes from a Git repository, the root problem is simple: Bundler needs the git executable during deployment. The fix is either to stop depending on Git-sourced gems in production or to install Git early enough in the Beanstalk deployment lifecycle that Bundler can use it.

Why Bundler Needs Git

Bundler can install gems from RubyGems, local paths, or Git repositories. A Gemfile entry like this requires the git command:

ruby
gem "my_private_gem", git: "https://github.com/example/my_private_gem.git", branch: "main"

When Elastic Beanstalk runs bundle install, Bundler shells out to Git to clone or update that repository. If Git is not available, deployment fails even though the rest of the Ruby environment is fine.

First Question: Do You Need a Git-Based Gem at All?

The cleanest fix is often to avoid Git dependencies in production. If the gem can be published to RubyGems or a private gem server, deployment becomes much simpler and more reproducible.

That said, some teams do pin directly to a repository or commit. In that case, the environment must have Git installed before Bundler runs.

Installing Git on Elastic Beanstalk

The exact mechanism depends on the platform generation.

On older Elastic Beanstalk Linux environments, .ebextensions YAML files commonly installed packages. On newer Amazon Linux 2 and later platform branches, .platform/hooks is the modern mechanism for deployment customization.

A practical prebuild hook looks like this:

bash
1#!/bin/bash
2set -e
3
4yum install -y git

Save it as:

text
.platform/hooks/prebuild/10_install_git.sh

Then make it executable before you deploy:

bash
chmod +x .platform/hooks/prebuild/10_install_git.sh

Because the hook runs before application build steps finish, Git is available by the time Bundler needs it.

Older .ebextensions Pattern

If you are on an older Beanstalk platform that still relies on .ebextensions, the package declaration looks like this:

yaml
packages:
  yum:
    git: []

Save that in a file such as:

text
.ebextensions/01_packages.config

This approach is still useful when maintaining older environments, but for current Beanstalk platform customization, .platform/hooks is usually the more direct choice.

Verifying the Environment

Deployment logs are the first place to confirm the real failure mode. Look for Bundler messages saying Git could not be found or that a Git source could not be checked out.

It also helps to verify the Gemfile itself. If a dependency uses Git indirectly through another gem specification, the failure can look confusing until you inspect the resolved sources carefully.

Authentication Matters Too

Installing Git is only half the story for private repositories. If the repository is private, the environment also needs credentials that work non-interactively, such as a deploy key, a token, or an SSH configuration established during deployment.

That is one reason many teams choose to publish an internal gem instead. It reduces deployment moving parts and avoids embedding source-control authentication into the app environment.

Common Pitfalls

The biggest pitfall is installing Git too late in the deployment sequence. If Bundler runs before your customization step, the fix exists in the repository but still has no effect.

Another mistake is assuming every Beanstalk platform branch uses the same customization mechanism. Older .ebextensions advice may not match a newer Amazon Linux 2 based environment.

Developers also fix the missing executable and then hit a second failure because the Git repository is private and no credentials are configured. The deploy host needs both the tool and access.

Finally, do not ignore the simpler architectural fix: if the dependency can be packaged as a released gem, that is usually better than making production deployment depend on live Git access.

Summary

  • Bundler needs the git executable whenever a gem is sourced from a Git repository.
  • On current Elastic Beanstalk platforms, a .platform/hooks/prebuild script is a practical way to install Git before Bundler runs.
  • Older environments may still use .ebextensions package installation.
  • Private Git-based gems also require non-interactive credentials, not just the Git binary.
  • The most maintainable fix is often to avoid Git-sourced production gems when possible.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design