ZPY博客

mackbook安装brew报错failed to connect to raw githubusercontent com port 443 operation timed out

---
title: "mackbook安装brew报错Failed to connect to raw.githubusercontent.com port 443: Operation timed out"
date: 2019-11-04 08:02:44
categories: mac
tags:
- 报错
- 安装
- mac
- macbook
- github
- 脚本
- brew
- 443
- time out
- 翻墙
- ruby
---

今天在macbook上安装brew,安装命令为

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

但是一直报错Failed to connect to raw.githubusercontent.com port 443: Operation timed out

原本以是网不好,结果试了N次都不行。后来发现直接在浏览器上访问https://raw.githubusercontent.com/Homebrew/install/master/install也访问不了。。好吧,这个网址被墙了,只能翻墙才能访问到这个网址的内容,其实就是一个脚本。现在我把脚本内容贴出来。希望对无法翻墙的朋友有用。

将下面脚本复制后,保存为名为brew_install的文件。然后执行/usr/bin/ruby brew_install即可成功安装。

#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere (which is
# unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
BREW_REPO = "https://github.com/Homebrew/brew".freeze

# TODO: bump version when new macOS is released
MACOS_LATEST_SUPPORTED = "10.15".freeze
# TODO: bump version when new macOS is released
MACOS_OLDEST_SUPPORTED = "10.13".freeze

# no analytics during installation
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"] = "1"

# get nicer global variables
require "English"

module Tty
module_function

def blue
bold 34
end

def red
bold 31
end

def reset
escape 0
end

def bold(code = 39)
escape "1;#{code}"
end

def underline
escape "4;39"
end

def escape(code)
"\033[#{code}m" if STDOUT.tty?
end
end

class Array
def shell_s
cp = dup
first = cp.shift
cp.map { |arg| arg.gsub " ", "\\ " }.unshift(first).join(" ")
end
end

def ohai(*args)
puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}"
end

def warn(warning)
puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
end

def system(*args)
abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
end

def sudo(*args)
args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil?
ohai "/usr/bin/sudo", *args
system "/usr/bin/sudo", *args
end

def getc
system "/bin/stty raw -echo"
if STDIN.respond_to?(:getbyte)
STDIN.getbyte
else
STDIN.getc
end
ensure
system "/bin/stty -raw echo"
end

def wait_for_user
puts
puts "Press RETURN to continue or any other key to abort"
c = getc
# we test for \r and \n because some stuff does \r instead
abort unless (c == 13) || (c == 10)
end

class Version
include Comparable
attr_reader :parts

def initialize(str)
@parts = str.split(".").map(&:to_i)
end

def <=>(other)
parts <=> self.class.new(other).parts
end

def to_s
parts.join(".")
end
end

def macos_version
@macos_version ||= Version.new(`/usr/bin/sw_vers -productVersion`.chomp[/10\.\d+/])
end

def should_install_command_line_tools?
if macos_version > "10.13"
!File.exist?("/Library/Developer/CommandLineTools/usr/bin/git")
else
!File.exist?("/Library/Developer/CommandLineTools/usr/bin/git") ||
!File.exist?("/usr/include/iconv.h")
end
end

def user_only_chmod?(path)
return false unless File.directory?(path)

mode = File.stat(path).mode & 0777
# u = (mode >> 6) & 07
# g = (mode >> 3) & 07
# o = (mode >> 0) & 07
mode != 0755
end

def chmod?(path)
File.exist?(path) && !(File.readable?(path) && File.writable?(path) && File.executable?(path))
end

def chown?(path)
!File.owned?(path)
end

def chgrp?(path)
!File.grpowned?(path)
end

# USER isn't always set so provide a fall back for the installer and subprocesses.
ENV["USER"] ||= `id -un`.chomp

# Invalidate sudo timestamp before exiting (if it wasn't active before).
Kernel.system "/usr/bin/sudo -n -v 2>/dev/null"
at_exit { Kernel.system "/usr/bin/sudo", "-k" } unless $CHILD_STATUS.success?

# The block form of Dir.chdir fails later if Dir.CWD doesn't exist which I
# guess is fair enough. Also sudo prints a warning message for no good reason
Dir.chdir "/usr"

####################################################################### script
if RUBY_PLATFORM.to_s.downcase.include?("linux")
abort <<-EOABORT
To install Linuxbrew, paste at a terminal prompt:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
EOABORT
elsif macos_version < "10.7"
abort <<-EOABORT
Your Mac OS X version is too old. See:
#{Tty.underline}https://github.com/mistydemeo/tigerbrew#{Tty.reset}"
EOABORT
elsif macos_version < "10.9"
abort "Your OS X version is too old"
elsif Process.uid.zero?
abort "Don't run this as root!"
elsif !`dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include?("user is a member")
abort "This script requires the user #{ENV["USER"]} to be an Administrator."
elsif File.directory?(HOMEBREW_PREFIX) && (!File.executable? HOMEBREW_PREFIX)
abort <<-EOABORT
The Homebrew prefix, #{HOMEBREW_PREFIX}, exists but is not searchable. If this is
not intentional, please restore the default permissions and try running the
installer again:
sudo chmod 775 #{HOMEBREW_PREFIX}
EOABORT
# TODO: bump version when new macOS is released
elsif macos_version > MACOS_LATEST_SUPPORTED || macos_version < MACOS_OLDEST_SUPPORTED
who = "We"
if macos_version > MACOS_LATEST_SUPPORTED
what = "pre-release version"
elsif macos_version < MACOS_OLDEST_SUPPORTED
who << " (and Apple)"
what = "old version"
else
return
end
ohai "You are using macOS #{macos_version.parts.join(".")}."
ohai "#{who} do not provide support for this #{what}."

puts <<-EOS
This installation may not succeed.
After installation, you will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this #{what}.

EOS
end

ohai "This script will install:"
puts "#{HOMEBREW_PREFIX}/bin/brew"
puts "#{HOMEBREW_PREFIX}/share/doc/homebrew"
puts "#{HOMEBREW_PREFIX}/share/man/man1/brew.1"
puts "#{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
puts "#{HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
puts HOMEBREW_REPOSITORY.to_s

# Keep relatively in sync with
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/keg.rb
group_chmods = %w[bin etc include lib sbin share opt var
Frameworks
etc/bash_completion.d lib/pkgconfig
share/aclocal share/doc share/info share/locale share/man
share/man/man1 share/man/man2 share/man/man3 share/man/man4
share/man/man5 share/man/man6 share/man/man7 share/man/man8
var/log var/homebrew var/homebrew/linked
bin/brew]
.map { |d| File.join(HOMEBREW_PREFIX, d) }
.select { |d| chmod?(d) }
# zsh refuses to read from these directories if group writable
zsh_dirs = %w[share/zsh share/zsh/site-functions]
.map { |d| File.join(HOMEBREW_PREFIX, d) }
mkdirs = %w[bin etc include lib sbin share var opt
share/zsh share/zsh/site-functions
var/homebrew var/homebrew/linked
Cellar Caskroom Homebrew Frameworks]
.map { |d| File.join(HOMEBREW_PREFIX, d) }
.reject { |d| File.directory?(d) }

user_chmods = zsh_dirs.select { |d| user_only_chmod?(d) }
chmods = group_chmods + user_chmods
chowns = chmods.select { |d| chown?(d) }
chgrps = chmods.select { |d| chgrp?(d) }

unless group_chmods.empty?
ohai "The following existing directories will be made g