diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index e4ce548e7d..888c95cba2 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -724,7 +724,7 @@ then fi # Disable Ruby options we don't need. -RUBY_DISABLE_OPTIONS="--disable=rubyopt" +RUBY_DISABLE_OPTIONS="--disable=gems,rubyopt" if [[ -z "${HOMEBREW_RUBY_WARNINGS}" ]] then diff --git a/Library/Homebrew/standalone/load_path.rb b/Library/Homebrew/standalone/load_path.rb index 014590b087..7dbe4936f1 100644 --- a/Library/Homebrew/standalone/load_path.rb +++ b/Library/Homebrew/standalone/load_path.rb @@ -1,8 +1,12 @@ # typed: true # frozen_string_literal: true -require "pathname" +# We trust base Ruby to provide what we need. +# Don't look into the user-installed sitedir, which may contain older versions of RubyGems. +require "rbconfig" +$LOAD_PATH.reject! { |path| path.start_with?(RbConfig::CONFIG["sitedir"]) } +require "pathname" HOMEBREW_LIBRARY_PATH = Pathname(__dir__).parent.realpath.freeze require_relative "../utils/gems" diff --git a/Library/Homebrew/utils/gems.rb b/Library/Homebrew/utils/gems.rb index e0147d7b3c..ac9b69e7f0 100644 --- a/Library/Homebrew/utils/gems.rb +++ b/Library/Homebrew/utils/gems.rb @@ -44,6 +44,9 @@ module Homebrew end def setup_gem_environment!(setup_path: true) + require "rubygems" + raise "RubyGems too old!" if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.2.0") + # Match where our bundler gems are. gem_home = "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/ruby/#{RbConfig::CONFIG["ruby_version"]}" Gem.paths = {