Homebrew是什麼?它是Mac上的包管理器,類似CentOS的yum、Ubuntu的apt等,讓你下載、管理一條命令搞定,不需要每次去網上搜索、下載。HomeBrew是通過源碼的方式來安裝軟件,但是有時候我們安裝的軟件是GUI程序應用寶(.dmg/.pkg),這個時候我們就不能使用HomeBrew了,所以有了HomeBrew Cask的出現。
一、Homebrew
雖然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應用
待更新
二、Homebrew-cask
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