Skip to content

bundle lock does not respect Gemfile lockfile #9565

@tjvc

Description

@tjvc

Describe the problem as clearly as you can

#9059 introduced the ability to specify the lockfile path via the Gemfile DSL:

lockfile "Gemfile_next.lock"

However, bundle lock does not appear to use that value when writing the lock file.

From reading the implementation, this looks like it may be because Bundler::CLI::Lock falls back to Bundler.default_lockfile unless the command is called with the explicit --lockfile option.

Did you try upgrading rubygems & bundler?

The issue is present with version 4.0.12 of Bundler.

Post steps to reproduce the problem

  1. Create a project with a minimal Gemfile specifying a custom lockfile path (see the the bundle env output below for an example)
  2. Run bundle lock
  3. See that the lockfile is written to the default path, not the path specified in the Gemfile

Which command did you run?

bundle lock

What were you expecting to happen?

The lockfile is written to the path passed to lockfile in the Gemfile.

What happened instead?

The lockfile is written to the default lockfile path, i.e. Gemfile.lock.

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

Environment

Bundler       4.0.12
  Platforms   ruby, arm64-darwin-25
Ruby          4.0.5p0 (2026-05-20 revision 64336ffd0ee9e1f4c05891695a3d7b49cb709721) [arm64-darwin-25]
  Full Path   /Users/thom.carter/.asdf/installs/ruby/4.0.5/bin/ruby
  Config Dir  /Users/thom.carter/.asdf/installs/ruby/4.0.5/etc
RubyGems      4.0.10
  Gem Home    /Users/thom.carter/.asdf/installs/ruby/4.0.5/lib/ruby/gems/4.0.0
  Gem Path    /Users/thom.carter/.gem/ruby/4.0.0:/Users/thom.carter/.asdf/installs/ruby/4.0.5/lib/ruby/gems/4.0.0
  User Home   /Users/thom.carter
  User Path   /Users/thom.carter/.gem/ruby/4.0.0
  Bin Dir     /Users/thom.carter/.asdf/installs/ruby/4.0.5/bin
Tools         
  Git         2.52.0
  RVM         not installed
  rbenv       not installed
  chruby      not installed

Bundler Build Metadata

Timestamp  2026-05-26
Git SHA    665f998196

Gemfile

Gemfile

source "https://rubygems.org"

gem "rack"

lockfile "Gemfile_next.lock"

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    rack (3.2.6)

PLATFORMS
  arm64-darwin-25
  ruby

DEPENDENCIES
  rack

CHECKSUMS
  bundler (4.0.12) sha256=7f8b757d28dfb636e7b24fba2344ac6dd13b5b24f4b46d62573d483f211825ac
  rack (3.2.6) sha256=5ed78e1f73b2e25679bec7d45ee2d4483cc4146eb1be0264fc4d94cb5ef212c2

BUNDLED WITH
  4.0.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions