diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb
index 70a2386a928e509a17f61f5d3143d4353a8b2fd2..b16fb7a835b5d69602b675f093c37aa5045c862b 100644
--- a/Library/Homebrew/config.rb
+++ b/Library/Homebrew/config.rb
@@ -35,6 +35,11 @@ HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/")
 # Must use /tmp instead of $TMPDIR because long paths break Unix domain sockets
 HOMEBREW_TEMP = Pathname.new(ENV.fetch("HOMEBREW_TEMP", "/tmp"))
 
+# Set common tmpdir environment variables to HOMEBREW_TEMP
+ENV["TMPDIR"] = HOMEBREW_TEMP
+ENV["TEMP"] = HOMEBREW_TEMP
+ENV["TMP"] = HOMEBREW_TEMP
+
 unless defined? HOMEBREW_LIBRARY_PATH
   # Root of the Homebrew code base
   HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent