diff options
| author | Mike McQuaid | 2016-09-20 08:10:23 +0100 |
|---|---|---|
| committer | GitHub | 2016-09-20 08:10:23 +0100 |
| commit | 5d7911fa71c6b97b385e22d6ec738973d1bbd64b (patch) | |
| tree | ee34c90dd4ef7d3587167e9c7ca724b5d59480c3 /Library | |
| parent | 9412c89e2d035104b25cf334600fd31204044441 (diff) | |
| parent | 4c773725c7683ec624863459ac3b4a3237a7382f (diff) | |
| download | brew-5d7911fa71c6b97b385e22d6ec738973d1bbd64b.tar.bz2 | |
Merge pull request #1028 from penman/install_gems_to_gem_home
Use user GEM_HOME for installing gems
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/brew.sh | 4 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 13 |
2 files changed, 14 insertions, 3 deletions
diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index d33cc8678..daf53823f 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -59,6 +59,10 @@ then odie "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" fi +# Save value to use for installing gems +export GEM_OLD_HOME="$GEM_HOME" +export GEM_OLD_PATH="$GEM_PATH" + # Users may have these set, pointing the system Ruby # at non-system gem paths unset GEM_HOME diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index cda67a8c6..8121b7146 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -270,17 +270,24 @@ module Homebrew end def self.install_gem_setup_path!(name, version = nil, executable = name) - require "rubygems" + # Respect user's preferences for where gems should be installed. + ENV["GEM_HOME"] = ENV["GEM_OLD_HOME"].to_s + ENV["GEM_HOME"] = Gem.user_dir if ENV["GEM_HOME"].empty? + ENV["GEM_PATH"] = ENV["GEM_OLD_PATH"] unless ENV["GEM_OLD_PATH"].to_s.empty? + + # Make rubygems notice env changes. + Gem.clear_paths + Gem::Specification.reset # 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") + path.unshift("#{Gem.dir}/bin") ENV["PATH"] = path.join(File::PATH_SEPARATOR) if Gem::Specification.find_all_by_name(name, version).empty? ohai "Installing or updating '#{name}' gem" - install_args = %W[--no-ri --no-rdoc --user-install #{name}] + install_args = %W[--no-ri --no-rdoc #{name}] install_args << "--version" << version if version # Do `gem install [...]` without having to spawn a separate process or |
