Homebrew是Mac OSX下利用的包管理工具,用来安装OSX系统中没有预装但是你须要的东西。它将软件包安装到独立目录,并在/usr/local目录下创建软链接。
安装Homebrew安装
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
办理 “curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused” 缺点前往www.ipaddress.com网站查询raw.githubusercontent.com主机的真实IP

修正/etc/hosts文件,添加以下内容:
199.232.68.133 raw.githubusercontent.com
利用阿里云镜像加速软件包下载
# 更换brew.gitcd "$(brew --repo)"git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git# 更换homebrew-core.gitgit clone git://mirrors.ustc.edu.cn/homebrew-core.git/ "$(brew --repo)/Library/Taps/homebrew/homebrew-core" --depth=1cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git# 生效brew update# 更换homebrew-bottlestouch ~/.bash_profileif [ -f ~/.bash_profile ];thenecho 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profilesource ~/.bash_profilefitouch ~/.zshrcif [ -f ~/.zshrc ];thenecho 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrcsource ~/.zshrcfi
利用Homebrew
根本语法
# 查看版本号brew --version# 实行子命令brew 子命令 [--verbose|-v] [选项]
安装软件包
brew install 软件包名# 例如:安装wgetbrew install wget
更新软件包
brew upgrade 软件包名# 例如: 更新wgetbrew upgrade wget
卸载已安装的软件包
brew uninstall 软件包名# 例如:卸载wgetbrew uninstall wget
清理旧版本软件包
brew cleanup
列出所有已安装的软件包
brew list
获取已安装软件包详情
brew info 软件包# 例如:获取wget详情brew info wget
查询可用软件包
# 按文本查询brew search 软件包名# 正则表达式查询brew search /正则表达式/# 例如:查询PHP可用包brew search php
显示软件包依赖列表
brew deps 软件包名# 例如:显示PHP的依赖brew deps php
检测Homebrew是否有问题
brew doctor
更新Homebrew
brew update
规复默认配置
出于某些场景, 可能须要回退到默认配置, 你可以通过下述办法回退到默认配置。实行命令
# 重置brew.git:$ cd "$(brew --repo)"$ git remote set-url origin https://github.com/Homebrew/brew.git# 重置homebrew-core.git:$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"$ git remote set-url origin https://github.com/Homebrew/homebrew-core.git
从以下文件中删掉 HOMEBREW_BOTTLE_DOMAIN 环境变量
~/.bash_profile
或
~/.zshrc