Homebrew进阶使用教程(一)

5,392 阅读2分钟

【homebrew 系列文章】

  1. HomeBrew常规使用教程
  2. Homebrew进阶使用教程(一)
  3. Homebrew进阶使用教程(二)-用一个命令行天气客户端构建自己的仓库
  4. Homebrew进阶使用教程(三)-apue.h在mac下安装并使用连接

我的github地址:github地址:https://github.com/rangaofei/homebrew-saka

更换国内源

自己写了一个安装时的脚本来在安装时选择国内源: github地址:https://github.com/rgf456/HomebrewInstall 基于官方脚本修改:

1.启动iterm终端,输入以下命令:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/rgf456/HomebrewInstall/master/install.rb)"

此时会自动执行脚本,输出以下内容:

 ~/ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/rgf456/HomebrewInstall/master/install.rb)"
请输入您要选择的源
  0.HomeBrew官方镜像:
    brew: https://github.com/Homebrew/brew
    core: https://github.com/Homebrew/homebrew-core
  1.清华大学镜像:
    brew: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
    core: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
  2.中科大镜像:
    brew: https://mirrors.ustc.edu.cn/brew.git
    core: https://mirrors.ustc.edu.cn/homebrew-core.git
-------------请输入0,1,2选择源地址--------------

2.选择对应的源编号,输入对应的数字,即可使用相应的源

0
你选择的是官方镜像

请忽略警告

假如输入的不是0、1、2中的一个数字,则会提示默认选择官方安装.

3.官方流程

==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN to continue or any other key to abort

点击enter等待安装完成

安装完成后 执行

cd "$(brew --repo)" 
git remote -v

即可看到是否更换了镜像地址:

 ~/ cd "$(brew --repo)"                
 /usr/local/Homebrew/ [stable] git remote -v
origin	https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git (fetch)
origin	https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git (push)
rgf456	https://github.com/rgf456/brew (fetch)
rgf456	https://github.com/rgf456/brew (push)

假如不想采用我的脚本安装,而是想自己指定的话:

以下是手动替换清华镜像的官方教程,逐条命令行执行即可。

cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

brew update

查找homebrew的缓存路径

执行如下命令

brew --cache

一般情况下是如下路径~/Library/Caches/Homebrew

直接进入缓存路径

cd (brew --cache)

此时直接进入了缓存目录。

缓存目录可在安装时指定:(不建议) 首先下载安装脚本:

https://raw.githubusercontent.com/Homebrew/install/master/install 将这个脚本内容保存至本地随便命名install 下载好install脚本后,找到HOMEBREW_CACHE变量,修改为自己想要的文件夹,然后执行安装命令:

/usr/bin/ruby -e "$(cat install)"

即可安装homebrew。

卸载homebrew

执行如下命令

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"