换了新电脑
只用了一年的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/