mac 安装 brew 错误及解决方案

首先安装的时候报错:
fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.

然后还报github安装错误的。

    

==> Downloading and installing Homebrew...

remote: Enumerating objects: 5, done.

remote: Counting objects: 100% (5/5), done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 5 (delta 3), reused 5 (delta 3), pack-reused 0

Unpacking objects: 100% (5/5), done.

From https://github.com/Homebrew/brew

   145f29fc5..a98bbbc64  master     -> origin/master

HEAD is now at a98bbbc64 Merge pull request #6305 from Homebrew/dependabot/bundler/docs/html-proofer-3.11.1

fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.

Use '--' to separate paths from revisions, like this:

'git <command> [<revision>...] -- [<file>...]'

^C-e:68:in `system': Interrupt

from -e:68:in `system'

from -e:360:in `block in <main>'

from -e:342:in `chdir'

from -e:342:in `<main>'

解决方案 先卸载再安装

卸载方式:

打开:https://raw.githubusercontent.com/Homebrew/install/master/uninstall

然后将网页上的内容保存下来,存储为uninstall的文件名后

chmod 755 uninstall

./uninstall 或者执行 ruby  unstall 文件执行卸载

unstall文件的内容如下:

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby

require "English"
require "fileutils"
require "optparse"
require "pathname"

# Default options
options = {
  :force               => false,
  :quiet               => false,
  :dry_run             => false,
  :skip_cache_and_logs => false,
}

# global status to indicate whether there is anything wrong.
@failed = false

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 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

class Pathname
  def resolved_path
    symlink? ? dirname+readlink : self
  end

  def /(other)
    self + other.to_s
  end

  def pretty_print
    if symlink?
      puts to_s + " -> " + resolved_path.to_s
    elsif directory?
      puts to_s + "/"
    else
      puts to_s
    end
  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)
  return if Kernel.system(*args)

  warn "Failed during: #{args.shell_s}"
  @failed = true
end

####################################################################### script

homebrew_prefix_candidates = []

OptionParser.new do |opts|
  opts.banner = "Homebrew Uninstaller\nUsage: ./uninstall [options]"
  opts.summary_width = 16
  opts.on("-pPATH", "--path=PATH", "Sets Homebrew prefix. Defaults to /usr/local.") do |p|
    homebrew_prefix_candidates << Pathname.new(p)
  end
  opts.on("--skip-cache-and-logs", "Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.") do
    options[:skip_cache_and_logs] = true
  end
  opts.on("-f", "--force", "Uninstall without prompting.") { options[:force] = true }
  opts.on("-q", "--quiet", "Suppress all output.") { options[:quiet] = true }
  opts.on("-d", "--dry-run", "Simulate uninstall but don't remove anything.") do
    options[:dry_run] = true
  end
  opts.on_tail("-h", "--help", "Display this message.") do
    puts opts
    exit
  end
end.parse!

if homebrew_prefix_candidates.empty? # Attempt to locate Homebrew unless `--path` is passed
  prefix =
    begin
      `brew --prefix`
    rescue
      ""
    end
  homebrew_prefix_candidates << Pathname.new(prefix.strip) unless prefix.empty?
  prefix =
    begin
      begin
        `command -v brew`
      rescue
        `which brew`
      end
    rescue
      ""
    end
  homebrew_prefix_candidates << Pathname.new(prefix.strip).dirname.parent unless prefix.empty?
  homebrew_prefix_candidates << Pathname.new("/usr/local") # Homebrew default path
  homebrew_prefix_candidates << Pathname.new("#{ENV["HOME"]}/.linuxbrew") # Linuxbrew default path
end

HOMEBREW_PREFIX = homebrew_prefix_candidates.find do |p|
  next unless p.directory?
  if p.to_s == "/usr/local" && File.exist?("/usr/local/Homebrew/.git")
    next true
  end

  (p/".git").exist? || (p/"bin/brew").executable?
end
abort "Failed to locate Homebrew!" if HOMEBREW_PREFIX.nil?

HOMEBREW_REPOSITORY = if (HOMEBREW_PREFIX/".git").exist?
  (HOMEBREW_PREFIX/".git").realpath.dirname
elsif (HOMEBREW_PREFIX/"bin/brew").exist?
  (HOMEBREW_PREFIX/"bin/brew").realpath.dirname.parent
end
abort "Failed to locate Homebrew!" if HOMEBREW_REPOSITORY.nil?

HOMEBREW_CELLAR = if (HOMEBREW_PREFIX/"Cellar").exist?
  HOMEBREW_PREFIX/"Cellar"
else
  HOMEBREW_REPOSITORY/"Cellar"
end

gitignore =
  begin
    (HOMEBREW_REPOSITORY/".gitignore").read
  rescue Errno::ENOENT
    `curl -fsSL https://raw.githubusercontent.com/Homebrew/brew/master/.gitignore`
  end
abort "Failed to fetch Homebrew .gitignore!" if gitignore.empty?

homebrew_files = gitignore.split("\n")
                          .select { |line| line.start_with? "!" }
                          .map { |line| line.chomp("/").gsub(%r{^!?/}, "") }
                          .reject { |line| %w[bin share share/doc].include?(line) }
                          .map { |p| HOMEBREW_REPOSITORY/p }
if HOMEBREW_PREFIX.to_s != HOMEBREW_REPOSITORY.to_s
  homebrew_files << HOMEBREW_REPOSITORY
  homebrew_files += %w[
    bin/brew
    etc/bash_completion.d/brew
    share/doc/homebrew
    share/man/man1/brew.1
    share/man/man1/brew-cask.1
    share/zsh/site-functions/_brew
    share/zsh/site-functions/_brew_cask
    var/homebrew
  ].map { |p| HOMEBREW_PREFIX/p }
else
  homebrew_files << HOMEBREW_REPOSITORY/".git"
end
homebrew_files << HOMEBREW_CELLAR
homebrew_files << HOMEBREW_PREFIX/"Caskroom"

unless options[:skip_cache_and_logs]
  homebrew_files += %W[
    #{ENV["HOME"]}/Library/Caches/Homebrew
    #{ENV["HOME"]}/Library/Logs/Homebrew
    /Library/Caches/Homebrew
    #{ENV["HOME"]}/.cache/Homebrew
    #{ENV["HOMEBREW_CACHE"]}
    #{ENV["HOMEBREW_LOGS"]}
  ].map { |p| Pathname.new(p) }
end

if RUBY_PLATFORM.to_s.downcase.include? "darwin"
  homebrew_files += %W[
    /Applications
    #{ENV["HOME"]}/Applications
  ].map { |p| Pathname.new(p) }.select(&:directory?).map do |p|
    p.children.select do |app|
      app.resolved_path.to_s.start_with? HOMEBREW_CELLAR.to_s
    end
  end.flatten
end

homebrew_files = homebrew_files.select(&:exist?).sort

unless options[:quiet]
  warn "This script #{options[:dry_run] ? "would" : "will"} remove:"
  homebrew_files.each(&:pretty_print)
end

if STDIN.tty? && (!options[:force] && !options[:dry_run])
  STDERR.print "Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] "
  abort unless gets.rstrip =~ /y|yes/i
end

ohai "Removing Homebrew installation..." unless options[:quiet]
paths = %w[Frameworks bin etc include lib opt sbin share var]
        .map { |p| HOMEBREW_PREFIX/p }
        .select(&:exist?)
        .map(&:to_s)
if paths.any?
  args = %w[-E] + paths + %w[-regex .*/info/([^.][^/]*\.info|dir)]
  if options[:dry_run]
    args << "-print"
  else
    args += %w[-exec /bin/bash -c]
    args << "/usr/bin/install-info --delete --quiet {} \"$(dirname {})/dir\""
    args << ";"
  end
  puts "Would delete:" if options[:dry_run]
  system "/usr/bin/find", *args
  args = paths + %w[-type l -lname */Cellar/*]
  if options[:dry_run]
    args << "-print"
  else
    args += %w[-exec unlink {} ;]
  end
  puts "Would delete:" if options[:dry_run]
  system "/usr/bin/find", *args
end

homebrew_files.each do |file|
  if options[:dry_run]
    puts "Would delete #{file}"
  else
    begin
      FileUtils.rm_rf(file)
    rescue => e
      warn "Failed to delete #{file}"
      puts e.message
      @failed = true
    end
  end
end

# Invalidate sudo timestamp before exiting
at_exit { Kernel.system "/usr/bin/sudo", "-k" }

def sudo(*args)
  ohai "/usr/bin/sudo", *args
  system "/usr/bin/sudo", *args
end

ohai "Removing empty directories..." unless options[:quiet]
paths = %w[bin etc include lib opt sbin share var
           Caskroom Cellar Homebrew Frameworks]
        .map { |p| HOMEBREW_PREFIX/p }
        .select(&:exist?)
        .map(&:to_s)
if paths.any?
  args = paths + %w[-name .DS_Store]
  if options[:dry_run]
    args << "-print"
  else
    args << "-delete"
  end
  puts "Would delete:" if options[:dry_run]
  sudo "/usr/bin/find", *args
  args = paths + %w[-depth -type d -empty]
  if options[:dry_run]
    args << "-print"
  else
    args += %w[-exec rmdir {} ;]
  end
  puts "Would remove directories:" if options[:dry_run]
  sudo "/usr/bin/find", *args
end

if options[:dry_run]
  exit
else
  if HOMEBREW_PREFIX.to_s != "/usr/local" && HOMEBREW_PREFIX.exist?
    sudo "rmdir", HOMEBREW_PREFIX.to_s
  end
  if HOMEBREW_PREFIX.to_s != HOMEBREW_REPOSITORY.to_s && HOMEBREW_REPOSITORY.exist?
    sudo "rmdir", HOMEBREW_REPOSITORY.to_s
  end
end

unless options[:quiet]
  if @failed
    warn "Homebrew partially uninstalled (but there were steps that failed)!"
    puts "To finish uninstalling rerun this script with `sudo`."
  else
    ohai "Homebrew uninstalled!"
  end
end

residual_files = []
residual_files.concat(HOMEBREW_REPOSITORY.children) if HOMEBREW_REPOSITORY.exist?
residual_files.concat(HOMEBREW_PREFIX.children) if HOMEBREW_PREFIX.exist?
residual_files.uniq!

unless residual_files.empty? || options[:quiet]
  puts "The following possible Homebrew files were not deleted:"
  residual_files.each(&:pretty_print)
  puts "You may wish to remove them yourself.\n"
end

exit 1 if @failed

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值