用 Homebrew 带飞你的 Mac
Homebrew也称brew,macOS下基于命令行的最强大软件包管理工具,使用Ruby语言开发。类似于CentOS的yum或者Ubuntu的apt-get,brew能方便的管理软件的安装、更新、卸载,省去了手动编译或拖动安装的不便,更使得软件的管理更加集中化,解决了依赖包管理的烦恼。
安装
Homebrew 依赖于Xcode Command Line Tools,所以需先执行:
1
|
xcode-select --install |
在终端中执行:
1
|
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
检查是否已安装成功:
1
2
3
4
|
$ brew -v Homebrew 1.6.1 Homebrew/homebrew-core (git revision 0aeb7; last commit 2018-04-12) |
基本用法
基于brew安装的所有软件及其依赖均会安装到目录/usr/local/Cellar
- Brew 帮助信息
$ brew help Example usage: brew search [TEXT|/REGEX/] brew info [FORMULA...] brew install FORMULA... brew update brew upgrade [FORMULA...] brew uninstall FORMULA... brew list [FORMULA...] Troubleshooting: brew config brew doctor brew install --verbose --debug FORMULA Contributing: brew create [URL [--no-fetch]] brew edit [FORMULA...] Further help: brew commands brew help [COMMAND] man brew https://docs.brew.sh
- 子命令帮助信息
brew help [COMMAND]或brew [COMMAND] -h用于查看具体某个子命令的帮助信息。 - 服务管理
brew services用于方便的管理 brew 安装的软件软件,类似于 Linux 下的 service 命令。 - 查看
brew services帮助信息:
$ brew services
brew services command:
Integrates Homebrew formulae with macOS' launchctl manager.
[sudo] brew services list
List all running services for the current user (or root)
[sudo] brew services run formula|--all
Run the service formula without starting at login (or boot).
[sudo] brew services start formula|--all
Start the service formula immediately and register it to launch at login (or boot).
[sudo] brew services stop formula|--all
Stop the service formula immediately and unregister it from launching at login (or boot).
[sudo] brew services restart formula|--all
Stop (if necessary) and start the service immediately and register it to launch at login (or boot).
[sudo] brew services cleanup
Remove all unused services.
If sudo is passed, operate on /Library/LaunchDaemons (started at boot).
Otherwise, operate on ~/Library/LaunchAgents (started at login).
|
- 查询服务列表:
$ brew services list Name Status User Plist redis stopped php56 started shocker /usr/local/opt/php56/homebrew.mxcl.php56.plist mongodb started shocker /usr/local/opt/mongodb/homebrew.mxcl.mongodb.plist memcached stopped httpd stopped nginx started shocker /usr/local/opt/nginx/homebrew.mxcl.nginx.plist etcd stopped mysql@5.6 started shocker /usr/local/opt/mysql@5.6/homebrew.mxcl.mysql@5.6.plist
- 检查可更新的软件列表
brew outdated可查询有更新版本的软件
brew outdated wget (1.18) < 1.19.4_1 redis (3.2.8) < 4.0.9 brotli (1.0.3) < 1.0.4 glib (2.56.0) < 2.56.1 etcd (3.2.6) < 3.3.3 tmux (2.3_2) < 2.6 openssl@1.1 (1.1.0e) < 1.1.0h mysql@5.6 (5.6.34) < 5.6.39 libzip (1.5.0) < 1.5.1 bash-completion (1.3_1) < 1.3_3
- 清理软件
brew cleanup -n列出需要清理的内容brew cleanup清理所有的过时软件brew cleanup [FORMULA]清理指定软件的过时包 - 查看配置信息
brew config用于查看 brew 所在环境及相关的配置情况 -
诊断问题
brew doctor诊断当前 brew 存在哪些问题,并给出解决方案 -
仓库管理
brew tap已安装的仓库列表
$ brew tap Updating Homebrew... caskroom/cask homebrew/core homebrew/services peckrob/php phinze/cask
brew tap [--full] user/repo [URL] 添加仓库
brew untap tap 移除仓库
浙公网安备 33010602011771号