From 8dc1e05ff87d22f37261945e465cea23b1343c2c Mon Sep 17 00:00:00 2001 From: Martin Afanasjew Date: Tue, 5 Jan 2016 01:09:54 +0100 Subject: [PATCH] utils: inject Ruby path when running Gems Particularly the `bundler` Gem requires the right Ruby binary to be in the PATH to work correctly if the Ruby binary used to run Homebrew is overridden via `HOMEBREW_RUBY_PATH` and thus intentionally not prefixed to the PATH (as that would affect formulae with a Ruby dependency). The workaround here is to prefix this path only when a Gem is activated via `Homebrew.install_gem_setup_path!` (currently used in `brew man`, `brew style`, and `brew tests`). --- Library/Homebrew/utils.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index bad26dfac1..d9a41b86dc 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -231,7 +231,12 @@ module Homebrew def self.install_gem_setup_path!(gem, version = nil, executable = gem) require "rubygems" - ENV["PATH"] = "#{Gem.user_dir}/bin:#{ENV["PATH"]}" + + # Add Gem binary directory and (if missing) Ruby binary directory to PATH. + path = ENV["PATH"].split(File::PATH_SEPARATOR) + path.unshift(RUBY_BIN) if which("ruby") != RUBY_PATH + path.unshift("#{Gem.user_dir}/bin") + ENV["PATH"] = path.join(File::PATH_SEPARATOR) if Gem::Specification.find_all_by_name(gem, version).empty? ohai "Installing or updating '#{gem}' gem"