1、简介
官网:Homebrew — The Missing Package Manager for macOS (or Linux)
所以,它是个包管理器,就像Linux系统的yum、apt-get神器,brew是MacOS系统中的神器。可以通过brew来安装大部分软件。
- 安装的软件都来源于官网,安全。
- brew会管理软件的依赖和库,在不造成冗余的同时,大大缩短软件包的编译时间。
它的使用很简单,参考 yum 的使用,比如我们要安装 git :
# 确认需要安装的软件存在,不是必须的的
$ yum search git
# 安装软件
$ yum install git
使用brew类似:
# 搜索需要安装的软件是否存在,不是必须的
$ brew search git
# 安装软件
$ brew install git
是不是看起来好像没什么区别,其实一模一样。
2、安装
安装直接参考官网,如上图的命令,拷贝后直接在Mac的命令行运行即可:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
如果提示连接失败:
Failed to connect to http://raw.githubusercontent.com port 443: Connection refused.
如果没有科学上网,这时可以使用国内gitee源来进行安装:
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
3、配置使用
在国内使用,我们最好是配置一下Homebrew源:
3.1 替换brew.git
$ cd "$(brew --repo)"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
3.2 替换homebrew-core.git
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
3.3 替换homebrew-bottles
# 中国科大:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
3.4 最后更新使配置生效
$ brew update
4、Formulae和Casks
brew安装的软件分为两类:Formulae和Casks。
比如我们搜索一下 music:
Formulae和Cask本质上也没啥区别,也比较好区分:
- 「Formulae」一般是那些命令行工具、开发库、字体、插件等不含 GUI 界面的软件。
- 「Cask」是指那些含有 GUI 图形化界面的软件,如 Google Chrome、FireFox 、Atom 等。
软件包下载完成后,若是 CLI 命令会自动软链接至 /usr/local/bin
目录。如果是基于 ARM 的 macOS 则会软链接至 /opt/homebrew/bin
目录。
5、常用命令
# 查找软件
$ brew search wget
# 安装软件
$ brew install wget
# 查看软件信息
$ brew info wget
# 列出已安装的软件
$ brew list
# 列出已安装的formulae
$ brew list --formulae
# 列出已安装的cask
$ brew list --cask
# 列出可更新的软件
$ brew outdated
# 更新软件
$ brew upgrade wget
# 清理旧版本软件
$ brew cleanup wget
# 清理所有旧版本软件
$ brew cleanup
# 查看可清理的旧版本包,并不真正的清理
$ brew cleanup -n
6、参考
MacOS更换brew源
Homebrew 使用详解,macOS 的第二个 Mac App Store文章来源:https://www.toymoban.com/news/detail-823504.html
mac下更新brew国内源文章来源地址https://www.toymoban.com/news/detail-823504.html
到了这里,关于【开发环境】macOS中包管理器brew的使用入门的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!