美文网首页
macOS 安装 Homebrew

macOS 安装 Homebrew

作者: SilveryYan | 来源:发表于2019-12-14 16:03 被阅读0次

我可能就是闲的很,想搞事情,Homebrew的镜像换来换去结果出了很多问题。于是就倒腾了以下,就简单的记录下吧。我不知道其他人有没有遇到过这种情况,反正我是不会把镜像源换来换去了...

下载安装脚本

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> ~/Desktop/brew_install.rb && vsc ~/Desktop/brew_install.rb

PS. vscVScode命令,也可以用其他编辑器打开,比如vim

如果安装了VS code,但没有命令,可以执行以下语句。如果觉得vsc不太适合,也可以换成别的

ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/vsc

修改安装脚本

  1. 修改上游镜像

    找到这一行语句

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

    替换成以下语句

    BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
    

    PS. 这里采用的是清华大学的Homebrew上游镜像,当然你也可以使用其他的国内镜像

  2. 注释自更新语句

    注释前

    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", BREW_REPO
      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"
    
      system "git", "fetch", "origin", "master:refs/remotes/origin/master",
             "--tags", "--force"
    
      system "git", "reset", "--hard", "origin/master"
    
      system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"
    
      system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force"
    end
    

    注释后

    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", BREW_REPO
      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"
    
      system "git", "fetch", "origin", "master:refs/remotes/origin/master",
             "--tags", "--force"
    
      system "git", "reset", "--hard", "origin/master"
    
      system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"
    
      # system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force"
    end
    

开始安装

/usr/bin/ruby ~/Desktop/brew_install.rb

PS. 由于我已经安装成功,无法上传安装成功后的截图

RUBY

Homebrewruby版本有一定的需求,在不满足的情况下会重新下载,那么这里我们手动下载。如果觉得麻烦也可以直接跳过这一步,反正包也不大

cat /usr/local/Homebrew/Library/Homebrew/cmd/vendor-install.sh | grep mavericks.bottle.tar.gz

如果没有对Homebrew安装位置进行修改的话,执行以上命令会得到两个url链接

Homebrew Ruby Download Url

直接用第二个链接去下载,下载完成之后移动到以下目录

mv ~/Downloads/portable-ruby-2.6.3.mavericks.bottle.tar.gz ~/Library/Caches/Homebrew

CORE和CASK

  1. 手动同步homebrew/core

    git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git $(brew --repo homebrew/core) --depth 1
    
  2. 手动同步homebrew/cask

    git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git $(brew --repo homebrew/cask) --depth 1
    

初始化和更新

brew update --force

验证镜像

git -C $(brew --repo) remote -v
git -C $(brew --repo homebrew/core) remote -v
git -C $(brew --repo homebrew/cask) remote -v
Homebrew镜像验证

Homebrew-bottles 镜像

这个比较简单,请点这里

相关文章

网友评论

      本文标题:macOS 安装 Homebrew

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