Homebrew是什么?它是Mac上的包管理器,类似CentOS的yum、Ubuntu的apt等,让你下载、管理一条命令搞定,不需要每次去网上搜索、下载。HomeBrew是通过源码的方式来安装软件,但是有时候我们安装的软件是GUI程序应用宝(.dmg/.pkg),这个时候我们就不能使用HomeBrew了,所以有了HomeBrew Cask的出现。
虽然macOS上的命令行界面具有很多在Linux和其他Unix系统中可以找到的功能,但它没有附带一个好的包管理器。 包管理器是一组软件工具,可用于自动执行软件安装,配置和升级。 他们将安装的软件保存在一个中心位置,并且可以使用常用的格式维护系统上的所有软件包。 Homebrew是一个免费的开源软件包管理系统,可以简化macOS上的软件安装。
Homebrew官网:https://brew.sh/index_zh-cn。
1. 安装brew,一般直接在终端直接输入命令即可。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
但在国内安装时,由于网络的问题会报错“curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused”。
解决方法:使用 sudo vim /etc/hosts 命令编辑hosts文件,添加以下内容并保存
199.232.68.133 raw.githubusercontent.com
再次输入上面安装brew的那一条命令就可以下载了。
Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in
Bash. Please migrate to the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Enumerating objects: 43, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 140733 (delta 0), reused 43 (delta 0), pack-reused 140690
Receiving objects: 100% (140733/140733), 34.63 MiB | 52.00 KiB/s, done.
Resolving deltas: 100% (103587/103587), done.
From https://github.com/Homebrew/brew
* [new branch] master -> origin/master
* [new tag] 0.1 -> 0.1
* [new tag] 0.2 -> 0.2
* [new tag] 0.3 -> 0.3
* [new tag] 0.4 -> 0.4
* [new tag] 0.5 -> 0.5
* [new tag] 0.6 -> 0.6
* [new tag] 0.7 -> 0.7
* [new tag] 0.7.1 -> 0.7.1
* [new tag] 0.8 -> 0.8
* [new tag] 0.8.1 -> 0.8.1
* [new tag] 0.9 -> 0.9
* [new tag] 0.9.1 -> 0.9.1
* [new tag] 0.9.2 -> 0.9.2
* [new tag] 0.9.3 -> 0.9.3
* [new tag] 0.9.4 -> 0.9.4
* [new tag] 0.9.5 -> 0.9.5
* [new tag] 0.9.8 -> 0.9.8
* [new tag] 0.9.9 -> 0.9.9
* [new tag] 1.0.0 -> 1.0.0
* [new tag] 1.0.1 -> 1.0.1
* [new tag] 1.0.2 -> 1.0.2
* [new tag] 1.0.3 -> 1.0.3
* [new tag] 1.0.4 -> 1.0.4
* [new tag] 1.0.5 -> 1.0.5
* [new tag] 1.0.6 -> 1.0.6
* [new tag] 1.0.7 -> 1.0.7
* [new tag] 1.0.8 -> 1.0.8
* [new tag] 1.0.9 -> 1.0.9
* [new tag] 1.1.0 -> 1.1.0
* [new tag] 1.1.1 -> 1.1.1
* [new tag] 1.1.10 -> 1.1.10
* [new tag] 1.1.11 -> 1.1.11
* [new tag] 1.1.12 -> 1.1.12
* [new tag] 1.1.13 -> 1.1.13
* [new tag] 1.1.2 -> 1.1.2
* [new tag] 1.1.3 -> 1.1.3
* [new tag] 1.1.4 -> 1.1.4
* [new tag] 1.1.5 -> 1.1.5
* [new tag] 1.1.6 -> 1.1.6
* [new tag] 1.1.7 -> 1.1.7
* [new tag] 1.1.8 -> 1.1.8
* [new tag] 1.1.9 -> 1.1.9
* [new tag] 1.2.0 -> 1.2.0
* [new tag] 1.2.1 -> 1.2.1
* [new tag] 1.2.2 -> 1.2.2
* [new tag] 1.2.3 -> 1.2.3
* [new tag] 1.2.4 -> 1.2.4
* [new tag] 1.2.5 -> 1.2.5
* [new tag] 1.2.6 -> 1.2.6
* [new tag] 1.3.0 -> 1.3.0
* [new tag] 1.3.1 -> 1.3.1
* [new tag] 1.3.2 -> 1.3.2
* [new tag] 1.3.3 -> 1.3.3
* [new tag] 1.3.4 -> 1.3.4
* [new tag] 1.3.5 -> 1.3.5
* [new tag] 1.3.6 -> 1.3.6
* [new tag] 1.3.7 -> 1.3.7
* [new tag] 1.3.8 -> 1.3.8
* [new tag] 1.3.9 -> 1.3.9
* [new tag] 1.4.0 -> 1.4.0
* [new tag] 1.4.1 -> 1.4.1
* [new tag] 1.4.2 -> 1.4.2
* [new tag] 1.4.3 -> 1.4.3
* [new tag] 1.5.0 -> 1.5.0
* [new tag] 1.5.1 -> 1.5.1
* [new tag] 1.5.10 -> 1.5.10
* [new tag] 1.5.11 -> 1.5.11
* [new tag] 1.5.12 -> 1.5.12
* [new tag] 1.5.13 -> 1.5.13
* [new tag] 1.5.14 -> 1.5.14
* [new tag] 1.5.2 -> 1.5.2
* [new tag] 1.5.3 -> 1.5.3
* [new tag] 1.5.4 -> 1.5.4
* [new tag] 1.5.5 -> 1.5.5
* [new tag] 1.5.6 -> 1.5.6
* [new tag] 1.5.7 -> 1.5.7
* [new tag] 1.5.8 -> 1.5.8
* [new tag] 1.5.9 -> 1.5.9
* [new tag] 1.6.0 -> 1.6.0
* [new tag] 1.6.1 -> 1.6.1
* [new tag] 1.6.10 -> 1.6.10
* [new tag] 1.6.11 -> 1.6.11
* [new tag] 1.6.12 -> 1.6.12
* [new tag] 1.6.13 -> 1.6.13
* [new tag] 1.6.14 -> 1.6.14
* [new tag] 1.6.15 -> 1.6.15
* [new tag] 1.6.16 -> 1.6.16
* [new tag] 1.6.17 -> 1.6.17
* [new tag] 1.6.2 -> 1.6.2
* [new tag] 1.6.3 -> 1.6.3
* [new tag] 1.6.4 -> 1.6.4
* [new tag] 1.6.5 -> 1.6.5
* [new tag] 1.6.6 -> 1.6.6
* [new tag] 1.6.7 -> 1.6.7
* [new tag] 1.6.8 -> 1.6.8
* [new tag] 1.6.9 -> 1.6.9
* [new tag] 1.7.0 -> 1.7.0
* [new tag] 1.7.1 -> 1.7.1
* [new tag] 1.7.2 -> 1.7.2
* [new tag] 1.7.3 -> 1.7.3
* [new tag] 1.7.4 -> 1.7.4
* [new tag] 1.7.5 -> 1.7.5
* [new tag] 1.7.6 -> 1.7.6
* [new tag] 1.7.7 -> 1.7.7
* [new tag] 1.8.0 -> 1.8.0
* [new tag] 1.8.1 -> 1.8.1
* [new tag] 1.8.2 -> 1.8.2
* [new tag] 1.8.3 -> 1.8.3
* [new tag] 1.8.4 -> 1.8.4
* [new tag] 1.8.5 -> 1.8.5
* [new tag] 1.8.6 -> 1.8.6
* [new tag] 1.9.0 -> 1.9.0
* [new tag] 1.9.1 -> 1.9.1
* [new tag] 1.9.2 -> 1.9.2
* [new tag] 1.9.3 -> 1.9.3
* [new tag] 2.0.0 -> 2.0.0
* [new tag] 2.0.1 -> 2.0.1
* [new tag] 2.0.2 -> 2.0.2
* [new tag] 2.0.3 -> 2.0.3
* [new tag] 2.0.4 -> 2.0.4
* [new tag] 2.0.5 -> 2.0.5
* [new tag] 2.0.6 -> 2.0.6
* [new tag] 2.1.0 -> 2.1.0
* [new tag] 2.1.1 -> 2.1.1
* [new tag] 2.1.10 -> 2.1.10
* [new tag] 2.1.11 -> 2.1.11
* [new tag] 2.1.12 -> 2.1.12
* [new tag] 2.1.13 -> 2.1.13
* [new tag] 2.1.14 -> 2.1.14
* [new tag] 2.1.15 -> 2.1.15
* [new tag] 2.1.16 -> 2.1.16
* [new tag] 2.1.2 -> 2.1.2
* [new tag] 2.1.3 -> 2.1.3
* [new tag] 2.1.4 -> 2.1.4
* [new tag] 2.1.5 -> 2.1.5
* [new tag] 2.1.6 -> 2.1.6
* [new tag] 2.1.7 -> 2.1.7
* [new tag] 2.1.8 -> 2.1.8
* [new tag] 2.1.9 -> 2.1.9
* [new tag] 2.2.0 -> 2.2.0
* [new tag] 2.2.1 -> 2.2.1
* [new tag] 2.2.10 -> 2.2.10
* [new tag] 2.2.11 -> 2.2.11
* [new tag] 2.2.12 -> 2.2.12
* [new tag] 2.2.13 -> 2.2.13
* [new tag] 2.2.14 -> 2.2.14
* [new tag] 2.2.15 -> 2.2.15
* [new tag] 2.2.16 -> 2.2.16
* [new tag] 2.2.17 -> 2.2.17
* [new tag] 2.2.2 -> 2.2.2
* [new tag] 2.2.3 -> 2.2.3
* [new tag] 2.2.4 -> 2.2.4
* [new tag] 2.2.5 -> 2.2.5
* [new tag] 2.2.6 -> 2.2.6
* [new tag] 2.2.7 -> 2.2.7
* [new tag] 2.2.8 -> 2.2.8
* [new tag] 2.2.9 -> 2.2.9
* [new tag] 2.3.0 -> 2.3.0
* [new tag] 2.4.0 -> 2.4.0
* [new tag] 2.4.1 -> 2.4.1
* [new tag] 2.4.2 -> 2.4.2
* [new tag] 2.4.3 -> 2.4.3
HEAD is now at 4290789dc Merge pull request #7898 from Rylan12/keg-only-audit
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 70, done.
remote: Counting objects: 100% (70/70), done.
remote: Compressing objects: 100% (46/46), done.
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
Failed during: /usr/local/bin/brew update --force
什么!又报错了!!!没关系,兵来将挡,水来土掩!
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
Failed during: /usr/local/bin/brew update --force
这个错误的原因还不知道是为什么(上面明明已经改了源的),可以试着打开https://mirrors.ustc.edu.cn/brew.git ,看到地址其实是好的。
那么就是git 的clone 失败了,那解决办法就是我们自己clone一下吧。
1.首先进入下载了一半的brew目录
cd "$(brew --repo)"
2.进入准备下载homebrew-core的目录
cd Library/Taps/
在这里建立两层目录
mkdir homebrew
cd homebrew/
mkdir homebrew-core
3.进入目录
cd homebrew-core/
4.开始clone
git clone git://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
命令如下,
$ cd "$(brew --repo)"
$ cd Library/Taps/
Taps$ mkdir homebrew
Taps$ cd homebrew/
home-brew$ mkdir homebrew-core
homebrew$ cd homebrew-core/
homebrew-core$ git clone git://mirrors.ustc.edu.cn/homebrew-core.git
一会就下载完了,运行结果如下,brew就可以用了。
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 743937, done.
remote: Total 743937 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (743937/743937), 241.36 MiB | 5.81 MiB/s, done.
Resolving deltas: 100% (496485/496485), done.
2. 检查是否安装成功
使用brew -v命令查看其版本
$ brew -v
Homebrew 2.4.3
Homebrew/homebrew-core (git revision 8abf26; last commit 2020-07-05)
3. 配置国内镜像源(Homebrew原生的当然是国外源,平时安装下载时会很慢,这里推荐两个镜像源,分别是中科大镜像源和清华镜像源两个,这里选的中科大镜像源)
# 替换homebrew默认源
$ cd "$(brew --repo)"
Homebrew$ git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
# 替换homebrew-core源
Homebrew$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
homebrew-core$ git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git
# 设置 bintray镜像
homebrew-core$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
homebrew-core$ source ~/.bash_profile
# brew更新
homebrew-core$ brew update
这样操作之后,homebrew就可以快速下载了。
4. brew应用
待更新
brew cask 是在brew 的基础上一个增强的工具,用来安装Mac上的Gui程序应用包(.dmg/.pkg), 比如qq、chrome等。它先下载解压到统一的目录中(/opt/homebrew-cask/Caskroom),省掉了自己去下载、解压、拖拽(安装)等步骤,同样,卸载相当容易与干净。然后再软链到~/Applications/目录下, 非常方便,而且还包含很多在 AppStore 里没有的常用软件。
brew cask的官网是:http://caskroom.io
github地址是:https://github.com/caskroom/homebrew-cask
参考链接:
https://blog.csdn.net/z69183787/article/details/87010890
https://blog.csdn.net/weixin_40879140/article/details/89963244
https://blog.csdn.net/zhang165849/article/details/72528645