Skip to content

Why does bundler cache gems into local install path? #6102

@blowfishpro

Description

@blowfishpro

Describe the problem as clearly as you can

When the path option is set, bundler puts a cache of all the .gem files into the local install path (e.g. vendor/bundle) even though they are not needed for deployment.

Did you try upgrading rubygems & bundler?

yes (rubygems 3.3.26 and bundler 2.3.26)

Post steps to reproduce the problem

Tested in the official Ruby 3.1.2 Docker library image (ruby:3.1.2)

gem update --system --no-doc
mkdir /tmp/example
cd /tmp/example
bundle init
bundle add rake
bundle config set --local path vendor/bundle

Which command did you run?

bundle install
ls vendor/bundle/ruby/3.1.0/cache/

What were you expecting to happen?

vendor/bundle contains only the installed gems, not the packaged .gem files

What actually happened?

.gem files appear to be cached into vendor/bundle/ruby/3.1.0/cache/.

After removing them and running some tests they do not appear to be needed for bundler to work correctly. While harmless in principle, they can potentially add a lot of disk usage. This is not ideal when trying to package for deployment (e.g. in a docker container).

I tried various combinations of settings and other tricks:

  • global_gem_cache setting
  • BUNDLE_USER_CACHE environment variable
  • deployment setting
  • packaging and then installing in separate steps:
    bundle config set --local no_install true
    bundle cache
    bundle install --local
    in this case the .gem files end up both in vendor/cache and vendor/bundle/ruby/3.1.0/cache/

Is there a way to get rid of this cache other than manually deleting all the .gem files? If bundler needs a cache for downloads that's fine, but it seems like it shouldn't be here.

If not included with the output of your command, run bundle env and paste the output below

Environment

Bundler       2.3.26
  Platforms   ruby, aarch64-linux
Ruby          3.1.2p20 (2022-04-12 revision 4491bb740a9506d76391ac44bb2fe6e483fec952) [aarch64-linux]
  Full Path   /usr/local/bin/ruby
  Config Dir  /usr/local/etc
RubyGems      3.3.26
  Gem Home    /usr/local/bundle
  Gem Path    /root/.local/share/gem/ruby/3.1.0:/usr/local/lib/ruby/gems/3.1.0:/usr/local/bundle
  User Home   /root
  User Path   /root/.local/share/gem/ruby/3.1.0
  Bin Dir     /usr/local/bundle/bin
Tools         
  Git         2.30.2
  RVM         not installed
  rbenv       not installed
  chruby      not installed

Bundler Build Metadata

Built At          2022-11-17
Git SHA           23ec5b8501
Released Version  true

Bundler settings

app_config
  Set via BUNDLE_APP_CONFIG: "/usr/local/bundle"
path
  Set for your local app (/usr/local/bundle/config): "vendor/bundle"
silence_root_warning
  Set via BUNDLE_SILENCE_ROOT_WARNING: true

Gemfile

Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

# gem "rails"

gem "rake", "~> 13.0"
Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    rake (13.0.6)

PLATFORMS
  aarch64-linux

DEPENDENCIES
  rake (~> 13.0)

BUNDLED WITH
   2.3.26

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions