Mac必备神器Homebrew
2019-01-06 本文已影响3人
程序员阿晨
1、Homebrew是什么?
引用官方的一句话:Homebrew是Mac OS 不可或缺的套件管理器。
Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。
2、Homebrew的安装方法
官网给出的安装方法:将以下命令粘贴到终端
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
但这种方法并不适用国内的Mac用户,因为网络资源的原因,电脑下载是龟速,实在是无法忍受,不信你自己试试就知道了。
解决下载慢有两个办法:
一是替换镜像源,将下载资源改为国内镜像资源即可(推荐)
二是科学上网,通过全局代理来进行安装,也是解决网络问题的一种方法(不推荐,不爱喝茶)
下面来说一下,怎样替换镜像源:
步骤一: 获取install文件:将以下命令粘贴到终端 + 回车
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
![](https://img.haomeiwen.com/i4677679/f6efbf3a53898d73.png)
![](https://img.haomeiwen.com/i4677679/e9f4a5534a16608a.png)
步骤二:更改文件中的链接资源,将原有的链接资源替换成清华大学的镜像资源
把这两句用#注释掉
BREW_REPO = "https://github.com/Homebrew/brew".freeze
CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
修改为这两句
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
CORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze
![](https://img.haomeiwen.com/i4677679/74c38b0b746e2e07.png)
步骤三:安装,运行修改了的brew_install,然后是漫长的等待
/usr/bin/ruby ~/brew_install
执行之后你会看到如下界面:
![](https://img.haomeiwen.com/i4677679/049cff5300e2fde2.png)
出现这个因为源不通,代码无法下载到本地,解决方法是更换成国内镜像源,执行如下命令,更换到中科院的镜像:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git//usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
然后把Homebrew-core的镜像地址也设置为中科院的国内镜像
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
执行更新brew命令:
brew update
接着执行brew检测命令:
brew doctor
![](https://img.haomeiwen.com/i4677679/0844348dffbc91b9.png)
让我们把默认源替换为国内USTC源:
(1) 替换核心软件仓库:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
(2) 替换cask软件仓库:
cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
(3) 替换Bottle源:
bash用户(shell用户):
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
zsh用户:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
Homebrew基本用法:
假设需要安装的软件是 wget
![](https://img.haomeiwen.com/i4677679/efc149ebd2a0fe0d.png)