diff --git a/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb b/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb index 3281441c93..4e28678bad 100644 --- a/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb +++ b/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb @@ -210,6 +210,17 @@ def run_load_path_setup_code(options) # # The existence of Gemfile/gems.rb indicates whether (2) is true: elsif File.exist?('Gemfile') || File.exist?('gems.rb') + # Bundler 2.5.12+ throws a hissy fit if you don't have the + # version of bundler installed with which the Gemfile.lock was + # created. This causes extremely inscrutible error messages such + # as `/usr/bin/ruby doesn't exist`, so we cause RubyGems to raise + # an intelligible error here instead. + if File.exist?('Gemfile.lock') + lockfile_contents = File.read('Gemfile.lock').lines.map(&:strip) + index = lockfile_contents.index 'BUNDLED WITH' + bundler_version = lockfile_contents[index + 1] unless index.nil? + found = Gem::Specification.find_by_name('bundler', "= #{bundler_version}") unless bundler_version.nil? + end # In case of Rails 3+, config/boot.rb already calls Bundler.setup. # However older versions of Rails may not so loading boot.rb might # not be the correct thing to do. To be on the safe side we