美文网首页
非墙安装homebrew/解决 curl: (7) Failed

非墙安装homebrew/解决 curl: (7) Failed

作者: Jesscia_Liu | 来源:发表于2020-03-04 12:56 被阅读0次
温馨提示:可墙小伙伴绕行

1.常规安装

打开终端输入:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

若未墙则会提示错误:

$ curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out

同时尝试在浏览器打开网址,发现打不开,则处于未墙状态。
https://raw.githubusercontent.com/Homebrew/install/master/install

解决方法:

方案一:找个可墙的朋友帮你打开这个网址,然后存成一份brew_install.txt文件发给你。
方案二:使用以下文本粘贴到一个brew_install.txt文件中。

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/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_CORE_TAP = "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core".freeze

HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze

HOMEBREW_OLD_CACHE = "/Library/Caches/Homebrew".freeze

#BREW_REPO = "https://github.com/Homebrew/brew".freeze

#BREW_REPO_INSECURE = "git://github.com/Homebrew/brew.git".freeze

#CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze

#CORE_TAP_REPO_INSECURE = "git://github.com/Homebrew/homebrew-core.git".freeze

BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze

BREW_REPO_INSECURE = "git://mirrors.ustc.edu.cn/brew.git".freeze

CORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze

CORE_TAP_REPO_INSECURE = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze

# TODO: bump version when new macOS is released

MACOS_LATEST_SUPPORTED = "10.14".freeze

# TODO: bump version when new macOS is released

MACOS_OLDEST_SUPPORTED = "10.12".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 { |p| p.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?

  return false if macos_version < "10.9"

  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 git

  @git ||= if ENV["GIT"] && File.executable?(ENV["GIT"])

    ENV["GIT"]

  elsif Kernel.system "/usr/bin/which -s git"

    "git"

  else

    exe = `xcrun -find git 2>/dev/null`.chomp

    exe if $CHILD_STATUS && $CHILD_STATUS.success? && !exe.empty? && File.executable?(exe)

  end

  return unless @git

  @git

end

def can_macos_use_tls12?

  macos_version >= "10.9"

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

# Invalidate sudo timestamp before exiting (if it wasn't active before).

Kernel.system "/usr/bin/sudo -n -v 2>/dev/null" unless macos_version < "10.7"

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

abort "See Linuxbrew: #{Tty.underline}http://linuxbrew.sh/#{Tty.reset}" if RUBY_PLATFORM.to_s.downcase.include?("linux")

abort "Mac OS X too old, see: #{Tty.underline}https://github.com/mistydemeo/tigerbrew#{Tty.reset}" if macos_version < "10.5"

abort "Don't run this as root!" if Process.uid.zero?

abort <<-EOABORT unless `dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include? "user is a member"

This script requires the user #{ENV["USER"]} to be an Administrator.

EOABORT

# Tests will fail if the prefix exists, but we don't have execution permissions.

# Abort in this case.

abort <<-EOABORT if File.directory?(HOMEBREW_PREFIX) && (!File.executable? HOMEBREW_PREFIX)

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

# Require preinstalled git binary if TLS 1.2 not built in.

if !can_macos_use_tls12? && !git

  puts "This version of Mac OS X requires Git to perform the installation."

  if macos_version == "10.5"

    abort "Install from: #{Tty.underline}http://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/git-osx-installer/git-1.7.5.4-i386-leopard.dmg#{Tty.reset}"

  elsif macos_version == "10.6"

    abort "Install from: #{Tty.underline}http://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/git-osx-installer/git-1.8.4.2-intel-universal-snow-leopard.dmg#{Tty.reset}"

  else

    abort "Install Xcode or the Command Line Tools: #{Tty.underline}https://developer.apple.com/download/more/#{Tty.reset}"

  end

end

# TODO: bump version when new macOS is released

if 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 and other breakages.

Please create pull requests instead of asking for help on Homebrew's

GitHub, Discourse, Twitter or IRC. As you are running this #{what},

you are responsible for resolving any issues you experience.

  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 group writable:"

  puts(*group_chmods)

end

unless user_chmods.empty?

  ohai "The following existing directories will be made writable by user only:"

  puts(*user_chmods)

end

unless chowns.empty?

  ohai "The following existing directories will have their owner set to #{Tty.underline}#{ENV["USER"]}#{Tty.reset}:"

  puts(*chowns)

end

unless chgrps.empty?

  ohai "The following existing directories will have their group set to #{Tty.underline}admin#{Tty.reset}:"

  puts(*chgrps)

end

unless mkdirs.empty?

  ohai "The following new directories will be created:"

  puts(*mkdirs)

end

if should_install_command_line_tools?

  ohai "The Xcode Command Line Tools will be installed."

end

wait_for_user if STDIN.tty? && !ENV["CI"]

if File.directory? HOMEBREW_PREFIX

  sudo "/bin/chmod", "u+rwx", *chmods unless chmods.empty?

  sudo "/bin/chmod", "g+rwx", *group_chmods unless group_chmods.empty?

  sudo "/bin/chmod", "755", *user_chmods unless user_chmods.empty?

  sudo "/usr/sbin/chown", ENV["USER"], *chowns unless chowns.empty?

  sudo "/usr/bin/chgrp", "admin", *chgrps unless chgrps.empty?

else

  sudo "/bin/mkdir", "-p", HOMEBREW_PREFIX

  sudo "/usr/sbin/chown", "root:wheel", HOMEBREW_PREFIX

end

unless mkdirs.empty?

  sudo "/bin/mkdir", "-p", *mkdirs

  sudo "/bin/chmod", "g+rwx", *mkdirs

  sudo "/bin/chmod", "755", *zsh_dirs

  sudo "/usr/sbin/chown", ENV["USER"], *mkdirs

  sudo "/usr/bin/chgrp", "admin", *mkdirs

end

[HOMEBREW_CACHE, HOMEBREW_OLD_CACHE].each do |cache|

  sudo "/bin/mkdir", "-p", cache unless File.directory? cache

  sudo "/bin/chmod", "g+rwx", cache if chmod? cache

  sudo "/usr/sbin/chown", ENV["USER"], cache if chown? cache

  sudo "/usr/bin/chgrp", "admin", cache if chgrp? cache

end

if should_install_command_line_tools?

  ohai "Searching online for the Command Line Tools"

  # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools

  clt_placeholder = "/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"

  sudo "/usr/bin/touch", clt_placeholder

  clt_macos_version = if macos_version == "10.9"

    "Mavericks"

  else

    macos_version

  end

  clt_sort = if macos_version >= "10.13"

    "sort -V"

  else

    "sort"

  end

  clt_label_command = "/usr/sbin/softwareupdate -l | " \

                      "grep -B 1 -E 'Command Line (Developer|Tools)' | " \

                      "awk -F'*' '/^ +\\*/ {print $2}' | " \

                      "grep '#{clt_macos_version}' | " \

                      "#{clt_sort} | " \

                      "sed 's/^ *//' | " \

                      "tail -n1"

  clt_label = `#{clt_label_command}`.chomp

  unless clt_label.empty?

    ohai "Installing #{clt_label}"

    sudo "/usr/sbin/softwareupdate", "-i", clt_label

    sudo "/bin/rm", "-f", clt_placeholder

    sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"

  end

end

# Headless install may have failed, so fallback to original 'xcode-select' method

if should_install_command_line_tools? && STDIN.tty?

  ohai "Installing the Command Line Tools (expect a GUI popup):"

  sudo "/usr/bin/xcode-select", "--install"

  puts "Press any key when the installation has completed."

  getc

  sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"

end

abort <<-EOABORT if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?

You have not agreed to the Xcode license.

Before running the installer again please agree to the license by opening

Xcode.app or running:

    sudo xcodebuild -license

EOABORT

ohai "Downloading and installing Homebrew..."

Dir.chdir HOMEBREW_REPOSITORY do

  # we do it in four steps to avoid merge errors when reinstalling

  system git, "init", "-q"

  # "git remote add" will fail if the remote is defined in the global config

  system git, "config", "remote.origin.url", can_macos_use_tls12? ? BREW_REPO : BREW_REPO_INSECURE

  system git, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"

  # ensure we don't munge line endings on checkout

  system git, "config", "core.autocrlf", "false"

  args = git, "fetch", "origin", "master:refs/remotes/origin/master",

        "--tags", "--force"

  system(*args)

  system git, "reset", "--hard", "origin/master"

  unless can_macos_use_tls12?

    system git, "clone", "--depth", "1", CORE_TAP_REPO_INSECURE, HOMEBREW_CORE_TAP

    system git, "config", "--file", "#{HOMEBREW_CORE_TAP}/.git/config", "core.autocrlf", "false"

    ENV["HOMEBREW_BOTTLE_DOMAIN"] = "http://homebrew.bintray.com"

  end

  system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"

  system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force"

end

warn "#{HOMEBREW_PREFIX}/bin is not in your PATH." unless ENV["PATH"].split(":").include? "#{HOMEBREW_PREFIX}/bin"

ohai "Installation successful!"

puts

# Use the shell's audible bell.

print "\a"

# Use an extra newline and bold to avoid this being missed.

ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics."

puts <<-EOS

#{Tty.bold}Read the analytics documentation (and how to opt-out) here:

  #{Tty.underline}https://docs.brew.sh/Analytics#{Tty.reset}

EOS

ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"

puts <<-EOS

  #{Tty.underline}https://github.com/Homebrew/brew#donations#{Tty.reset}

EOS

Dir.chdir HOMEBREW_REPOSITORY do

  system git, "config", "--local", "--replace-all", "homebrew.analyticsmessage", "true"

  system git, "config", "--local", "--replace-all", "homebrew.caskanalyticsmessage", "true"

end

ohai "Next steps:"

if macos_version < "10.9" && macos_version > "10.6"

  `/usr/bin/cc --version 2> /dev/null` =~ /clang-(\d{2,})/

  version = Regexp.last_match(1).to_i

  if version < 425

    puts "- Install the Command Line Tools for Xcode:"

    puts "    #{Tty.underline}https://developer.apple.com/download/more/#{Tty.reset}"

  end

elsif !File.exist? "/usr/bin/cc"

  puts "- Install Xcode:"

  puts "    #{Tty.underline}https://developer.apple.com/download/more/#{Tty.reset}"

end

puts "- Run `brew help` to get started"

puts "- Further documentation: "

puts "    #{Tty.underline}https://docs.brew.sh#{Tty.reset}"

2.使用刚才得到的brew_install.txt文件安装homebrew

  1. 终端输入(ruby后是brew_install.txt的路径)
$ ruby ~/brew_install.txt 

2.进入漫长的等待过程.....期间需要输入回车和开机密码
之后会自动安装一个Xcode Command Line Tool。
安装完后需要重回终端输入回车,接着下载等待,终端显示如下

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 77, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (44/44), done.
Receiving objects:  24% (167311/687566), 38.70 MiB | 7.00 KiB/s  

Tips:若源不对,可能会卡在了这个位置超时报错。若未报错则等待安装成功即可。

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 77, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (44/44), done.
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
Failed during: /usr/local/bin/brew update --force
LNdeMacBook-Pro:Desktop ln$ 

解决方法:终端键入如下代码

$ git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

回车后提示成功如下

Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 5144, done.
remote: Compressing objects: 100% (4945/4945), done.
remote: Total 5144 (delta 40), reused 884 (delta 3)
Receiving objects: 100% (5144/5144), 4.18 MiB | 1.61 MiB/s, done.
Resolving deltas: 100% (40/40), done.

再次终端输入以下命令,每行输入完后回车

$ cd "$(brew --repo)" 
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" 
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

更新homebrew

$ brew update

提示安装成功

Already up-to-date.

3.安装成功后查看当前安装版本

$ brew -v
Homebrew 2.2.7
Homebrew/homebrew-core (git revision 467d; last commit 2020-03-03)

参考文章
https://www.jianshu.com/p/7071c1419409
https://www.cnblogs.com/inaruto/p/11168588.html
https://www.cnblogs.com/yanht/p/brew-note.html

相关文章

网友评论

      本文标题:非墙安装homebrew/解决 curl: (7) Failed

      本文链接:https://www.haomeiwen.com/subject/ajvmlhtx.html