ruby/rubygems · error · GemfileLockNotFound

This Bundle hasn't been installed yet. Run `bundle install`

Error message

This Bundle hasn't been installed yet. Run `bundle install` to update and install the bundled gems.

What it means

Raised as Bundler::GemfileLockNotFound by targeted `bundle update` invocations (gem names, --group, --source, --ruby, --bundler) when Bundler.default_lockfile does not exist. A targeted update patches an existing Gemfile.lock; with no lockfile there is nothing to unlock, so bundler points at `bundle install` as the command that creates the lockfile (lib/bundler/cli/update.rb:41-44). A full `bundle update` bypasses this branch because it resolves from scratch.

Source

Thrown at lib/bundler/cli/update.rb:42

        if Bundler.settings[:update_requires_all_flag]
          raise InvalidOption, "To update everything, pass the `--all` flag."
        end
        SharedHelpers.feature_deprecated! "Pass --all to `bundle update` to update everything"
      elsif !full_update && options[:all]
        raise InvalidOption, "Cannot specify --all along with specific options."
      end

      conservative = options[:conservative]

      unlock = if full_update
        if conservative
          { conservative: conservative }
        else
          true
        end
      else
        unless Bundler.default_lockfile.exist?
          raise GemfileLockNotFound, "This Bundle hasn't been installed yet. " \
            "Run `bundle install` to update and install the bundled gems."
        end
        explicit_gems = gems.dup

        if groups.any?
          deps = Bundler.definition.dependencies.select {|d| (d.groups & groups).any? }
          gems.concat(deps.map(&:name))
        end

        {
          gems: gems,
          sources: sources,
          ruby: options[:ruby],
          conservative: conservative,
          bundler: update_bundler,
        }
      end

View on GitHub (pinned to 86cbb817a3)

Solutions

  1. Run `bundle install` first to create Gemfile.lock, then repeat `bundle update <gem>`
  2. If Gemfile.lock is gitignored, remove it from .gitignore and commit the lockfile so clones and CI start with one
  3. If a full re-resolve is wanted, run `bundle update` with no gem names, which does not require an existing lockfile
  4. Check BUNDLE_GEMFILE and the working directory when the lockfile exists somewhere else

Example fix

# before (fresh clone, no Gemfile.lock)
bundle update rails
# => This Bundle hasn't been installed yet.

# after
bundle install
bundle update rails
Defensive patterns

Strategy: validation

Validate before calling

# Fail fast in scripts before a targeted update
test -f Gemfile.lock || { echo "Gemfile.lock missing: run bundle install first" >&2; exit 1; }
bundle update "$@"

Try / catch

begin
  Bundler::CLI::Update.new(options, %w[rails]).run
rescue Bundler::GemfileLockNotFound => e
  warn e.message
  system("bundle", "install") || abort
end

Prevention

When it happens

Trigger: `bundle update rails` or `bundle update --group development` in a project that has a Gemfile but no Gemfile.lock yet; the same after a fresh clone of a repo that never committed the lockfile; a targeted update while BUNDLE_GEMFILE points at a Gemfile whose sibling lockfile is missing.

Common situations: Gemfile.lock gitignored by accident so fresh clones and CI have no lockfile; a brand-new project where bundle install was never run; Docker builds that copy Gemfile but not Gemfile.lock; running the command from the wrong directory.

Related errors


AI-assisted analysis of ruby/rubygems@86cbb817a3 (2026-08-23). Data as JSON: /api/errors/22bb44a26ee687f9. Report an issue: GitHub.