# Bundler vs RubyGems: como as dependências Ruby funcionam no CI

> Bundler vs RubyGems para CI de Ruby: installs de gems, Gemfile.lock, reprodutibilidade e caching. Como os dois se encaixam no seu pipeline.

Source: https://latchkey.dev/pt/learn/tool-comparisons/bundler-vs-rubygems  
Updated: 2026-06-26

Estes não são realmente rivais: o RubyGems instala gems, o Bundler as fixa e resolve - e no CI você quase sempre quer o Bundler por cima.

O RubyGems é o gerenciador de pacotes e cliente de registry do Ruby (gem install). O Bundler fica por cima, resolvendo um conjunto consistente de gems a partir de um Gemfile e travando-as no Gemfile.lock para installs reprodutíveis.

## Comparison

|  | RubyGems | Bundler |
| --- | --- | --- |
| Papel | Instalar gems individuais | Resolver + travar um conjunto de dependências |
| Lockfile | Nenhum | Gemfile.lock |
| Installs reprodutíveis | Só se você fixar manualmente | Sim (a partir do lock) |
| Comando de CI | gem install <gem> | bundle install / bundle ci |
| Relação | Camada subjacente | Construído sobre o RubyGems |

## No CI

Para aplicações você quer o Bundler: faça commit do Gemfile.lock e rode bundle install (com configurações --deployment / frozen) para que todo pipeline receba versões idênticas de gems. O gem install puro serve para instalar ferramentas CLI standalone num job, mas não te dá um ambiente de projeto reprodutível. O Bundler usa o RubyGems por baixo - eles cooperam em vez de competir.

## Faça cache das gems

Faça cache do diretório vendor/bundle (ou gem) chaveado no Gemfile.lock e defina o bundle path para que os installs sejam restaurados, não rebuscados. Qualquer versão de Ruby que você mire, o install roda nos runners de CI; runners gerenciados mais rápidos ajudam quando compilações de gems nativas dominam.

## Decide with your own numbers, not a feature table

Feature comparisons age badly and rarely decide anything, because both tools in a mature category can do the job. What differs is how each behaves on your repository, and that takes one afternoon to measure.

```Terminal
# time a cold install with each candidate, cache cleared
hyperfine --prepare "rm -rf node_modules" --warmup 1 \
  "<tool-a> install" "<tool-b> install"

# and the thing CI actually pays for: a cold run with no local cache
docker run --rm -v "$(pwd):/w" -w /w node:22 sh -c "<tool> install"
```

> Measure the cold path. Warm local benchmarks favour whichever tool you already have cached, which is exactly the condition a CI runner never has.

## What actually changes when you switch

- Lockfile format. A switch is a one-way door for anyone still on the old tool until everyone migrates, so plan it as a single coordinated change.
- Resolution strictness. Tools differ on whether an undeclared transitive import works, and the stricter one will surface latent bugs as new failures.
- CI cache configuration. The cache path and key differ per tool; carrying over the old ones silently disables caching.
- Everyone on the team and every runner must move together. Pin the version so they cannot drift.

## O veredito

Construindo uma app Ruby: use o Bundler com um Gemfile.lock commitado para installs reprodutíveis. Só precisa de uma ferramenta standalone num job: gem install basta. São camadas, não alternativas - o Bundler é o padrão certo para projetos.

## FAQ

### Bundler vs RubyGems: How Ruby Dependencies Work in CI?

RubyGems is Ruby's package manager and registry client (gem install). Bundler sits on top, resolving a consistent set of gems from a Gemfile and locking them in Gemfile.lock for reproducible installs.

### In CI?

For applications you want Bundler: commit Gemfile.lock and run bundle install (with --deployment / frozen settings) so every pipeline gets identical gem versions. Bare gem install is fine for installing standalone CLI tools in a job, but it does not give you a reproducible project environment.

### Cache the gems?

Cache the vendor/bundle (or gem) directory keyed on Gemfile.lock and set bundle path so installs are restored, not refetched. Whichever Ruby version you target, the install runs on CI runners; faster managed runners help when native gem compiles dominate.

### Which should I choose?

Building a Ruby app: use Bundler with a committed Gemfile.lock for reproducible installs. Just need a standalone tool in a job: gem install is enough. They are layers, not alternatives - Bundler is the right default for projects.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
