Mac安装brew(2020年踩过无数坑后亲测有效的方法)

换了新电脑

只用了一年的MacBook air因为内存和硬盘不够用光荣退休,更新了定制版的MacBook pro,开心之余也会因为要重新安装一次软件准备才入无数新的坑感到不安。果然在安装brew时就因为没有梯子尝试了多种方法无果。因此成功安装后记录下来以帮助需要的同学。

报错及其原因

许多攻略中安装brew都采用以下命令

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" 

但是都指明了要使用梯子,在2020年不使用梯子的话已经不是下载缓慢啦,而是会报错

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

原因是没有梯子访问不了网址https://raw.github.com/Homebrew/homebrew/go/install

解决方案

从网上查询了多种解决方案,包括使用中科大源等,感觉最合理可行的方案是既然网址访问不了,则直接从网上搜索别人下载的网址对应文件(brew_install.rb),之后再修改该文件中的源路径
https://raw.github.com/Homebrew/homebrew/go/install 变成中科大的路径。亲测成功有效。

具体步骤

1、新建文件夹 /usr/local/Homebrew

sudo mkdir /usr/local/homebrew

2、将以下文件保存到/usr/local/homebrew路径下

#!/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/
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值