介绍
经常使用Linux系统的人们,应该非常熟悉使用yum或apt-get来管理软件包。苹果Mac OSX既拥有Windows一样易用的图形操作界面,也拥有Linux强大的命令行操作。
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.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ "$(brew --repo)/Library/Taps/homebrew/homebrew-core" --depth=1
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 生效
brew update
# 替换homebrew-bottles
touch ~/.bash_profile
if [ -f ~/.bash_profile ];then
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
fi
touch ~/.zshrc
if [ -f ~/.zshrc ];then
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
fi
使用Homebrew
基础语法
# 查看版本号
brew --version
# 执行子命令
brew 子命令 [--verbose|-v] [选项]
安装软件包
brew install 软件包名
# 例如:安装wget
brew install wget
更新软件包
brew upgrade 软件包名
# 例如: 更新wget
brew upgrade wget
卸载已安装的软件包
brew uninstall 软件包名
# 例如:卸载wget
brew 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
?
本文暂时没有评论,来添加一个吧(●'◡'●)