Homebrew进阶使用教程(一)

【homebrew 系列文章】git

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

个人github地址:github地址:https://github.com/rangaofei/homebrew-sakagithub

更换国内源

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

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

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

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

 ~/ /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.选择对应的源编号,输入对应的数字,便可使用相应的源curl

0
你选择的是官方镜像
复制代码

请忽略警告post

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

3.官方流程ui

==> 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等待安装完成url

安装完成后 执行

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)"
复制代码
相关文章
相关标签/搜索