zoukankan      html  css  js  c++  java
  • Homebrew 换源安装与使用

    问题

    官方安装方式

    1.  
      /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    2.  
      复制代码

    网速好的可能就直接装好了 建议直接跳过 看看homebrew换源 我这里网速还行 但是安装后还是出错了

    安装后报错

    error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

    1.  
      error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
    2.  
      fatal: the remote end hung up unexpectedly
    3.  
      fatal: early EOF
    4.  
      fatal: index-pack failed
    5.  
      Failed during: git fetch origin master:refs/remotes/origin/master --tags --force
    6.  
      复制代码

    换源安装 Homebrew

    进入homebrew 本地安装

    如果 进不去上面的链接 1. 打开记事本 2.复制以下文档,保存为brew_install.rb 3.控制台运行 ruby brew_install.rb 完整路径

    1.  
      #!/usr/bin/ruby
    2.  
      # This script installs to /usr/local only. To install elsewhere (which is
    3.  
      # unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
    4.  
      # anywhere you like.
    5.  
      HOMEBREW_PREFIX = "/usr/local".freeze
    6.  
      HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
    7.  
      HOMEBREW_CORE_TAP = "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core".freeze
    8.  
      HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
    9.  
      BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
    10.  
      # TODO: bump version when new macOS is released
    11.  
      MACOS_LATEST_SUPPORTED = "10.14".freeze
    12.  
      # TODO: bump version when new macOS is released
    13.  
      MACOS_OLDEST_SUPPORTED = "10.12".freeze
    14.  
       
    15.  
      # no analytics during installation
    16.  
      ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
    17.  
      ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"] = "1"
    18.  
       
    19.  
      # get nicer global variables
    20.  
      require "English"
    21.  
       
    22.  
      module Tty
    23.  
      module_function
    24.  
       
    25.  
      def blue
    26.  
      bold 34
    27.  
      end
    28.  
       
    29.  
      def red
    30.  
      bold 31
    31.  
      end
    32.  
       
    33.  
      def reset
    34.  
      escape 0
    35.  
      end
    36.  
       
    37.  
      def bold(code = 39)
    38.  
      escape "1;#{code}"
    39.  
      end
    40.  
       
    41.  
      def underline
    42.  
      escape "4;39"
    43.  
      end
    44.  
       
    45.  
      def escape(code)
    46.  
      "33[#{code}m" if STDOUT.tty?
    47.  
      end
    48.  
      end
    49.  
       
    50.  
      class Array
    51.  
      def shell_s
    52.  
      cp = dup
    53.  
      first = cp.shift
    54.  
      cp.map { |arg| arg.gsub " ", "\ " }.unshift(first).join(" ")
    55.  
      end
    56.  
      end
    57.  
       
    58.  
      def ohai(*args)
    59.  
      puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}"
    60.  
      end
    61.  
       
    62.  
      def warn(warning)
    63.  
      puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
    64.  
      end
    65.  
       
    66.  
      def system(*args)
    67.  
      abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
    68.  
      end
    69.  
       
    70.  
      def sudo(*args)
    71.  
      args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil?
    72.  
      ohai "/usr/bin/sudo", *args
    73.  
      system "/usr/bin/sudo", *args
    74.  
      end
    75.  
       
    76.  
      def getc
    77.  
      system "/bin/stty raw -echo"
    78.  
      if STDIN.respond_to?(:getbyte)
    79.  
      STDIN.getbyte
    80.  
      else
    81.  
      STDIN.getc
    82.  
      end
    83.  
      ensure
    84.  
      system "/bin/stty -raw echo"
    85.  
      end
    86.  
       
    87.  
      def wait_for_user
    88.  
      puts
    89.  
      puts "Press RETURN to continue or any other key to abort"
    90.  
      c = getc
    91.  
      # we test for and because some stuff does instead
    92.  
      abort unless (c == 13) || (c == 10)
    93.  
      end
    94.  
       
    95.  
      class Version
    96.  
      include Comparable
    97.  
      attr_reader :parts
    98.  
       
    99.  
      def initialize(str)
    100.  
      @parts = str.split(".").map(&:to_i)
    101.  
      end
    102.  
       
    103.  
      def <=>(other)
    104.  
      parts <=> self.class.new(other).parts
    105.  
      end
    106.  
       
    107.  
      def to_s
    108.  
      parts.join(".")
    109.  
      end
    110.  
      end
    111.  
       
    112.  
      def macos_version
    113.  
      @macos_version ||= Version.new(`/usr/bin/sw_vers -productVersion`.chomp[/10.d+/])
    114.  
      end
    115.  
       
    116.  
      def should_install_command_line_tools?
    117.  
      if macos_version > "10.13"
    118.  
      !File.exist?("/Library/Developer/CommandLineTools/usr/bin/git")
    119.  
      else
    120.  
      !File.exist?("/Library/Developer/CommandLineTools/usr/bin/git") ||
    121.  
      !File.exist?("/usr/include/iconv.h")
    122.  
      end
    123.  
      end
    124.  
       
    125.  
      def user_only_chmod?(path)
    126.  
      return false unless File.directory?(path)
    127.  
       
    128.  
      mode = File.stat(path).mode & 0777
    129.  
      # u = (mode >> 6) & 07
    130.  
      # g = (mode >> 3) & 07
    131.  
      # o = (mode >> 0) & 07
    132.  
      mode != 0755
    133.  
      end
    134.  
       
    135.  
      def chmod?(path)
    136.  
      File.exist?(path) && !(File.readable?(path) && File.writable?(path) && File.executable?(path))
    137.  
      end
    138.  
       
    139.  
      def chown?(path)
    140.  
      !File.owned?(path)
    141.  
      end
    142.  
       
    143.  
      def chgrp?(path)
    144.  
      !File.grpowned?(path)
    145.  
      end
    146.  
       
    147.  
      # Invalidate sudo timestamp before exiting (if it wasn't active before).
    148.  
      Kernel.system "/usr/bin/sudo -n -v 2>/dev/null"
    149.  
      at_exit { Kernel.system "/usr/bin/sudo", "-k" } unless $CHILD_STATUS.success?
    150.  
       
    151.  
      # The block form of Dir.chdir fails later if Dir.CWD doesn't exist which I
    152.  
      # guess is fair enough. Also sudo prints a warning message for no good reason
    153.  
      Dir.chdir "/usr"
    154.  
       
    155.  
      ####################################################################### script
    156.  
      if RUBY_PLATFORM.to_s.downcase.include?("linux")
    157.  
      abort <<-EOABORT
    158.  
      To install Linuxbrew, paste at a terminal prompt:
    159.  
      sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
    160.  
      EOABORT
    161.  
      elsif macos_version < "10.7"
    162.  
      abort <<-EOABORT
    163.  
      Your Mac OS X version is too old. See:
    164.  
      #{Tty.underline}https://github.com/mistydemeo/tigerbrew#{Tty.reset}"
    165.  
      EOABORT
    166.  
      elsif macos_version < "10.9"
    167.  
      abort "Your OS X version is too old"
    168.  
      elsif Process.uid.zero?
    169.  
      abort "Don't run this as root!"
    170.  
      elsif !`dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include?("user is a member")
    171.  
      abort "This script requires the user #{ENV["USER"]} to be an Administrator."
    172.  
      elsif File.directory?(HOMEBREW_PREFIX) && (!File.executable? HOMEBREW_PREFIX)
    173.  
      abort <<-EOABORT
    174.  
      The Homebrew prefix, #{HOMEBREW_PREFIX}, exists but is not searchable. If this is
    175.  
      not intentional, please restore the default permissions and try running the
    176.  
      installer again:
    177.  
      sudo chmod 775 #{HOMEBREW_PREFIX}
    178.  
      EOABORT
    179.  
      # TODO: bump version when new macOS is released
    180.  
      elsif macos_version > MACOS_LATEST_SUPPORTED || macos_version < MACOS_OLDEST_SUPPORTED
    181.  
      who = "We"
    182.  
      if macos_version > MACOS_LATEST_SUPPORTED
    183.  
      what = "pre-release version"
    184.  
      elsif macos_version < MACOS_OLDEST_SUPPORTED
    185.  
      who << " (and Apple)"
    186.  
      what = "old version"
    187.  
      else
    188.  
      return
    189.  
      end
    190.  
      ohai "You are using macOS #{macos_version.parts.join(".")}."
    191.  
      ohai "#{who} do not provide support for this #{what}."
    192.  
       
    193.  
      puts <<-EOS
    194.  
      This installation may not succeed.
    195.  
      After installation, you will encounter build failures and other breakages.
    196.  
      Please create pull requests instead of asking for help on Homebrew's
    197.  
      GitHub, Discourse, Twitter or IRC. As you are running this #{what},
    198.  
      you are responsible for resolving any issues you experience.
    199.  
       
    200.  
      EOS
    201.  
      end
    202.  
       
    203.  
      ohai "This script will install:"
    204.  
      puts "#{HOMEBREW_PREFIX}/bin/brew"
    205.  
      puts "#{HOMEBREW_PREFIX}/share/doc/homebrew"
    206.  
      puts "#{HOMEBREW_PREFIX}/share/man/man1/brew.1"
    207.  
      puts "#{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
    208.  
      puts "#{HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
    209.  
      puts HOMEBREW_REPOSITORY.to_s
    210.  
       
    211.  
      # Keep relatively in sync with
    212.  
      # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/keg.rb
    213.  
      group_chmods = %w[bin etc include lib sbin share opt var
    214.  
      Frameworks
    215.  
      etc/bash_completion.d lib/pkgconfig
    216.  
      share/aclocal share/doc share/info share/locale share/man
    217.  
      share/man/man1 share/man/man2 share/man/man3 share/man/man4
    218.  
      share/man/man5 share/man/man6 share/man/man7 share/man/man8
    219.  
      var/log var/homebrew var/homebrew/linked
    220.  
      bin/brew]
    221.  
      .map { |d| File.join(HOMEBREW_PREFIX, d) }
    222.  
      .select { |d| chmod?(d) }
    223.  
      # zsh refuses to read from these directories if group writable
    224.  
      zsh_dirs = %w[share/zsh share/zsh/site-functions]
    225.  
      .map { |d| File.join(HOMEBREW_PREFIX, d) }
    226.  
      mkdirs = %w[bin etc include lib sbin share var opt
    227.  
      share/zsh share/zsh/site-functions
    228.  
      var/homebrew var/homebrew/linked
    229.  
      Cellar Caskroom Homebrew Frameworks]
    230.  
      .map { |d| File.join(HOMEBREW_PREFIX, d) }
    231.  
      .reject { |d| File.directory?(d) }
    232.  
       
    233.  
      user_chmods = zsh_dirs.select { |d| user_only_chmod?(d) }
    234.  
      chmods = group_chmods + user_chmods
    235.  
      chowns = chmods.select { |d| chown?(d) }
    236.  
      chgrps = chmods.select { |d| chgrp?(d) }
    237.  
       
    238.  
      unless group_chmods.empty?
    239.  
      ohai "The following existing directories will be made group writable:"
    240.  
      puts(*group_chmods)
    241.  
      end
    242.  
      unless user_chmods.empty?
    243.  
      ohai "The following existing directories will be made writable by user only:"
    244.  
      puts(*user_chmods)
    245.  
      end
    246.  
      unless chowns.empty?
    247.  
      ohai "The following existing directories will have their owner set to #{Tty.underline}#{ENV["USER"]}#{Tty.reset}:"
    248.  
      puts(*chowns)
    249.  
      end
    250.  
      unless chgrps.empty?
    251.  
      ohai "The following existing directories will have their group set to #{Tty.underline}admin#{Tty.reset}:"
    252.  
      puts(*chgrps)
    253.  
      end
    254.  
      unless mkdirs.empty?
    255.  
      ohai "The following new directories will be created:"
    256.  
      puts(*mkdirs)
    257.  
      end
    258.  
      if should_install_command_line_tools?
    259.  
      ohai "The Xcode Command Line Tools will be installed."
    260.  
      end
    261.  
       
    262.  
      wait_for_user if STDIN.tty? && !ENV["CI"]
    263.  
       
    264.  
      if File.directory? HOMEBREW_PREFIX
    265.  
      sudo "/bin/chmod", "u+rwx", *chmods unless chmods.empty?
    266.  
      sudo "/bin/chmod", "g+rwx", *group_chmods unless group_chmods.empty?
    267.  
      sudo "/bin/chmod", "755", *user_chmods unless user_chmods.empty?
    268.  
      sudo "/usr/sbin/chown", ENV["USER"], *chowns unless chowns.empty?
    269.  
      sudo "/usr/bin/chgrp", "admin", *chgrps unless chgrps.empty?
    270.  
      else
    271.  
      sudo "/bin/mkdir", "-p", HOMEBREW_PREFIX
    272.  
      sudo "/usr/sbin/chown", "root:wheel", HOMEBREW_PREFIX
    273.  
      end
    274.  
       
    275.  
      unless mkdirs.empty?
    276.  
      sudo "/bin/mkdir", "-p", *mkdirs
    277.  
      sudo "/bin/chmod", "g+rwx", *mkdirs
    278.  
      sudo "/bin/chmod", "755", *zsh_dirs
    279.  
      sudo "/usr/sbin/chown", ENV["USER"], *mkdirs
    280.  
      sudo "/usr/bin/chgrp", "admin", *mkdirs
    281.  
      end
    282.  
       
    283.  
      sudo "/bin/mkdir", "-p", HOMEBREW_CACHE unless File.directory? HOMEBREW_CACHE
    284.  
      sudo "/bin/chmod", "g+rwx", HOMEBREW_CACHE if chmod? HOMEBREW_CACHE
    285.  
      sudo "/usr/sbin/chown", ENV["USER"], HOMEBREW_CACHE if chown? HOMEBREW_CACHE
    286.  
      sudo "/usr/bin/chgrp", "admin", HOMEBREW_CACHE if chgrp? HOMEBREW_CACHE
    287.  
       
    288.  
      if should_install_command_line_tools?
    289.  
      ohai "Searching online for the Command Line Tools"
    290.  
      # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
    291.  
      clt_placeholder = "/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
    292.  
      sudo "/usr/bin/touch", clt_placeholder
    293.  
       
    294.  
      clt_macos_version = if macos_version == "10.9"
    295.  
      "Mavericks"
    296.  
      else
    297.  
      macos_version
    298.  
      end
    299.  
      clt_sort = if macos_version >= "10.13"
    300.  
      "sort -V"
    301.  
      else
    302.  
      "sort"
    303.  
      end
    304.  
      clt_label_command = "/usr/sbin/softwareupdate -l | "
    305.  
      "grep -B 1 -E 'Command Line (Developer|Tools)' | "
    306.  
      "awk -F'*' '/^ +\*/ {print $2}' | "
    307.  
      "grep '#{clt_macos_version}' | "
    308.  
      "#{clt_sort} | "
    309.  
      "sed 's/^ *//' | "
    310.  
      "tail -n1"
    311.  
      clt_label = `#{clt_label_command}`.chomp
    312.  
       
    313.  
      unless clt_label.empty?
    314.  
      ohai "Installing #{clt_label}"
    315.  
      sudo "/usr/sbin/softwareupdate", "-i", clt_label
    316.  
      sudo "/bin/rm", "-f", clt_placeholder
    317.  
      sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
    318.  
      end
    319.  
      end
    320.  
       
    321.  
      # Headless install may have failed, so fallback to original 'xcode-select' method
    322.  
      if should_install_command_line_tools? && STDIN.tty?
    323.  
      ohai "Installing the Command Line Tools (expect a GUI popup):"
    324.  
      sudo "/usr/bin/xcode-select", "--install"
    325.  
      puts "Press any key when the installation has completed."
    326.  
      getc
    327.  
      sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
    328.  
      end
    329.  
       
    330.  
      abort <<-EOABORT if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?
    331.  
      You have not agreed to the Xcode license.
    332.  
      Before running the installer again please agree to the license by opening
    333.  
      Xcode.app or running:
    334.  
      sudo xcodebuild -license
    335.  
      EOABORT
    336.  
       
    337.  
      ohai "Downloading and installing Homebrew..."
    338.  
      Dir.chdir HOMEBREW_REPOSITORY do
    339.  
      # we do it in four steps to avoid merge errors when reinstalling
    340.  
      system "git", "init", "-q"
    341.  
       
    342.  
      # "git remote add" will fail if the remote is defined in the global config
    343.  
      system "git", "config", "remote.origin.url", BREW_REPO
    344.  
      system "git", "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"
    345.  
       
    346.  
      # ensure we don't munge line endings on checkout
    347.  
      system "git", "config", "core.autocrlf", "false"
    348.  
       
    349.  
      system "git", "fetch", "origin", "master:refs/remotes/origin/master",
    350.  
      "--tags", "--force"
    351.  
       
    352.  
      system "git", "reset", "--hard", "origin/master"
    353.  
       
    354.  
      system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"
    355.  
       
    356.  
      system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force"
    357.  
      end
    358.  
       
    359.  
      warn "#{HOMEBREW_PREFIX}/bin is not in your PATH." unless ENV["PATH"].split(":").include? "#{HOMEBREW_PREFIX}/bin"
    360.  
       
    361.  
      ohai "Installation successful!"
    362.  
      puts
    363.  
       
    364.  
      # Use the shell's audible bell.
    365.  
      print "a"
    366.  
       
    367.  
      # Use an extra newline and bold to avoid this being missed.
    368.  
      ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics."
    369.  
      puts <<-EOS
    370.  
      #{Tty.bold}Read the analytics documentation (and how to opt-out) here:
    371.  
      #{Tty.underline}https://docs.brew.sh/Analytics#{Tty.reset}
    372.  
       
    373.  
      EOS
    374.  
       
    375.  
      ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
    376.  
      puts <<-EOS
    377.  
      #{Tty.underline}https://github.com/Homebrew/brew#donations#{Tty.reset}
    378.  
      EOS
    379.  
       
    380.  
      Dir.chdir HOMEBREW_REPOSITORY do
    381.  
      system "git", "config", "--local", "--replace-all", "homebrew.analyticsmessage", "true"
    382.  
      system "git", "config", "--local", "--replace-all", "homebrew.caskanalyticsmessage", "true"
    383.  
      end
    384.  
       
    385.  
      ohai "Next steps:"
    386.  
      puts "- Run `brew help` to get started"
    387.  
      puts "- Further documentation: "
    388.  
      puts " #{Tty.underline}https://docs.brew.sh#{Tty.reset}"
    389.  
       
    390.  
      复制代码
    漫长的等待 卡在了这一步
    1.  
      ==> Tapping homebrew/core
    2.  
       
    3.  
      Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
    4.  
      复制代码

    没找到解决的办法 ,所以我选择等待了 10分钟

    继续报错

    1. Error: Failure while executing; git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1 exited with 128.
    2. Error: Failure while executing; /usr/local/bin/brew tap homebrew/core exited with 1.

    解决

    1.  
      // 执行下面这句命令,更换为中科院的镜像:
    2.  
      git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
    3.  
       
    4.  
      // 把homebrew-core的镜像地址也设为中科院的国内镜像
    5.  
       
    6.  
      cd "$(brew --repo)"
    7.  
       
    8.  
      git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
    9.  
       
    10.  
      cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    11.  
       
    12.  
      git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
    13.  
       
    14.  
      // 更新
    15.  
      brew update
    16.  
       
    17.  
      // 使用
    18.  
      brew install node
    19.  
      复制代码

    致谢

    报错参考

    1. Error: Failure while executing; git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1 exited with 128.
    2. Error: Failure while executing; /usr/local/bin/brew tap homebrew/core exited with 1.

    摘自简书大佬 www.jianshu.com/p/9118ee9da…

    转载于:https://juejin.im/post/5cc5d5356fb9a0321d73b44b

  • 相关阅读:
    关于编码的问题(转)
    XML巩固
    浏览器兼容问题的解决方案
    JavaScript 全局变量命名空间生成函数
    表格的使用(转)
    post上传文件
    安装cocoapods
    UILabel内容模糊
    动态获取键盘高度
    iOS多线程同步锁
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/12346248.html
Copyright © 2011-2022 走看看