如何在mac中安装HomeBrew

如何在mac中安装HomeBrew

  1. 首先直接查看HomeBrew官网(https://brew.sh/)
    在这里插入图片描述
  2. 直接输入这条命令,会发现报错如下:
fatal: unable to access 'https://github.com/Homebrew/brew/': Could not resolve host: github.com
Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

解决方法:

  • 首先ping github.com:
PING github.com (52.74.223.119): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
  • 将该"52.74.223.119 github.com"地址填入host文件中
  • 关闭并重新打开终端
  1. 之后,我们可以直接输入上面这条指令
    但是。。。4、5k每秒,这什么概念。。。
    也就是说,100多M的homebrew需要下五六七八个小时,而且谁又能保证中途会不会断网或者是下载出错呢???
    所以,假如是在国外或者翻墙等,可以直接使用这条命令,否则,使用接下来的方法。

  2. 下载慢则使用下面的方法

  • curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install(这条命令的意思是获取install文件并将其保存名为brew_install)
  • 打开 brew_install 文件,修改如下:
    找到如下代码:
    BREW_REPO = “https://github.com/Homebrew/brew”.freeze
    CORE_TAP_REPO = https://github.com/Homebrew/homebrew-core“.freeze
    复制代码更改为:
    BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git ".freeze
    CORE_TAP_REPO = “https://mirrors.ustc.edu.cn/homebrew-core.git”.freeze
    注:新版本HomeBrew可能没有CORE_TAP_REPO这句代码,如果没有不用新增。
  • 执行脚本
    /usr/bin/ruby brew_install
  • 此时脚本应该停在
    ==> Tapping homebrew/core
    Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…
  • ctrl + c退出命令
  • 通过镜像获取相应包:git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
  • 将下好的brew仓库的远程git地址修改:
    • cd “$(brew --repo)”
    • git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
  • 把homebrew-core的镜像地址也设为中科院的国内镜像:
    • cd “$(brew --repo)/Library/Taps/homebrew/homebrew-core”
    • git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
  • 复制代码执行更新:brew update
  • 复制代码最后用这个命令检查无错误:brew doctor

至此,homebrew安装完毕

参考文章:
https://blog.csdn.net/DiyHzp/article/details/90763558#commentsedit
https://www.jianshu.com/p/ff2ad9599a06

发布了80 篇原创文章 · 获赞 91 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/YaoDeBiAn/article/details/103099295