diff --git a/bin/bundle b/bin/bundle
index f19acf5b5cc6e80139297e3e6ba9d2fff4153a21..eed4bb7738a9401f6d81cf83c8ed7f7416ca3684 100755
--- a/bin/bundle
+++ b/bin/bundle
@@ -1,3 +1,8 @@
 #!/usr/bin/env ruby
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+
+require 'bundler'
+
+ENV['BUNDLE_GEMFILE'] ||=
+  Bundler.settings[:gemfile] || File.expand_path('../Gemfile', __dir__)
+
 load Gem.bin_path('bundler', 'bundle')
diff --git a/bin/rspec b/bin/rspec
index 4236753c9c143873d97803284aaa3b5c2711aa1b..5aebc7336fed6fe9125db81770b0d70946821ee0 100755
--- a/bin/rspec
+++ b/bin/rspec
@@ -5,5 +5,5 @@ begin
 rescue LoadError => e
   raise unless e.message.include?('spring')
 end
-require 'bundler/setup'
+require_relative '../config/bundler_setup'
 load Gem.bin_path('rspec-core', 'rspec')
diff --git a/bin/rspec-stackprof b/bin/rspec-stackprof
index 3bef45c607c2e14f2f93c57bce7df525b0df9ef0..018bfe7da4b4ea52080d1154fb8e38a4de6ec533 100755
--- a/bin/rspec-stackprof
+++ b/bin/rspec-stackprof
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 
-require 'bundler/setup'
+require_relative '../config/bundler_setup'
 require 'stackprof'
 $:.unshift 'spec'
 require 'spec_helper'
diff --git a/config/boot.rb b/config/boot.rb
index 41bf7953737ab05edf8f14082ecbdbfcaea1479d..2b0c203d6b5fadb942b765c3cd677e98351341a2 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -1,6 +1,9 @@
 # frozen_string_literal: true
 
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+require 'bundler'
+
+ENV['BUNDLE_GEMFILE'] ||=
+  Bundler.settings[:gemfile] || File.expand_path('../Gemfile', __dir__)
 
 # Set up gems listed in the Gemfile.
 require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
diff --git a/config/bundler_setup.rb b/config/bundler_setup.rb
new file mode 100644
index 0000000000000000000000000000000000000000..ff62ec7e4e4f3bde67cfb18b3da825291e9083f8
--- /dev/null
+++ b/config/bundler_setup.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+require 'bundler'
+ENV['BUNDLE_GEMFILE'] ||= Bundler.settings[:gemfile]
+require 'bundler/setup'
diff --git a/ee/bin/geo_log_cursor b/ee/bin/geo_log_cursor
index b490436867d6279da0f289048e686fab79c8c1b6..dcafd96395372a511317d8793033063c52605948 100755
--- a/ee/bin/geo_log_cursor
+++ b/ee/bin/geo_log_cursor
@@ -1,8 +1,7 @@
 #!/usr/bin/env ruby
 # frozen_string_literal: true
 
-require 'rubygems'
-require 'bundler/setup'
+require_relative '../../config/bundler_setup'
 require 'optparse'
 
 def rails_path(relname)
diff --git a/qa/Dockerfile b/qa/Dockerfile
index ad4bffb3bf29c04efddf5d634bccd9715919ab66..13213c7c8c8b770d2a7c3a5a110d509e812ac13c 100644
--- a/qa/Dockerfile
+++ b/qa/Dockerfile
@@ -76,6 +76,7 @@ COPY ./config/initializers/0_inject_enterprise_edition_module.rb /home/gitlab/co
 # Copy VERSION to ensure the COPY succeeds to copy at least one file since ee/app/models/license.rb isn't present in FOSS
 # The [b] part makes ./ee/app/models/license.r[b] a pattern that is allowed to return no files (which is the case in FOSS)
 COPY VERSION ./ee/app/models/license.r[b] /home/gitlab/ee/app/models/
+COPY ./config/bundler_setup.rb /home/gitlab/config/
 COPY ./lib/gitlab.rb /home/gitlab/lib/
 COPY ./lib/gitlab/utils.rb /home/gitlab/lib/gitlab/
 COPY ./INSTALLATION_TYPE ./VERSION /home/gitlab/
diff --git a/qa/qa.rb b/qa/qa.rb
index 89721445f394187e0239ea71b9ad31255b0f778d..4d86a29aecf71ccab69533b03bda228b6c6450f0 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -8,7 +8,7 @@
 
 require_relative 'lib/gitlab'
 
-require 'bundler/setup'
+require_relative '../config/bundler_setup'
 Bundler.require(:default)
 
 module QA
diff --git a/scripts/setup-test-env b/scripts/setup-test-env
index ebd3a48ae15f689fb73dbdb1531c23919a20ceba..a81aaa5cda34b947b33988844a677bc20bf22661 100755
--- a/scripts/setup-test-env
+++ b/scripts/setup-test-env
@@ -2,7 +2,7 @@
 
 # frozen_string_literal: true
 
-require 'bundler/setup'
+require_relative '../config/bundler_setup'
 
 require 'request_store'
 require 'rake'
diff --git a/spec/fast_spec_helper.rb b/spec/fast_spec_helper.rb
index b06ebba3f6c86586c71bba468b4ff96808101a22..1485edcd97d79e41c0c6832d2ff7f010e8c21bb6 100644
--- a/spec/fast_spec_helper.rb
+++ b/spec/fast_spec_helper.rb
@@ -7,7 +7,7 @@
   return
 end
 
-require 'bundler/setup'
+require_relative '../config/bundler_setup'
 
 ENV['GITLAB_ENV'] = 'test'
 ENV['IN_MEMORY_APPLICATION_SETTINGS'] = 'true'