前言
在 macOS 下使用 homebrew 安裝軟件時,默認情況下安裝了最新的版本。有時候我們需要老版本的時候,homebrew 並沒有提供較爲便捷的方式。
本文以 protobuf 爲例講解 brew install
如何安裝指定版本軟件。
安裝
查找 rb 文件地址
❯ brew info protobuf
==> protobuf: stable 21.5 (bottled), HEAD
Protocol buffers (Google's data interchange format)
https://github.com/protocolbuffers/protobuf/
/usr/local/Cellar/protobuf/3.17.3_1 (263 files, 19.3MB) *
Poured from bottle on 2022-09-07 at 10:01:17
/usr/local/Cellar/protobuf/21.5 (279 files, 19MB)
Poured from bottle on 2022-09-07 at 09:40:56
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/protobuf.rb
License: BSD-3-Clause
==> Dependencies
Build: [email protected] ✘, [email protected] ✘
==> Options
--HEAD
Install HEAD version
==> Caveats
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/protobuf
==> Analytics
install: 191,131 (30 days), 490,097 (90 days), 1,535,759 (365 days)
install-on-request: 46,962 (30 days), 111,247 (90 days), 316,495 (365 days)
build-error: 157 (30 days
使用 brew info
獲取到 protobuf.rb
的地址爲 https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/protobuf.rb
查找指定版本 rb 文件
瀏覽器打開 protobuf.rb
的地址,並點擊 History
。
找到指定版本的 commit
(這裏以 3.19.4 版本爲例),並點擊 commit
號查看文件。
點擊 View file
查看文件內容。
點擊 Raw
。
保存 rb 文件
保存文件,並命名爲 protobuf.rb
。
這裏以保存到桌面爲例。
安裝指定版本 protobuf
❯ protoc --version
libprotoc 3.21.5
❯ cd ~/Desktop
❯ brew unlink protobuf
❯ brew install ./protobuf.rb
❯ protoc --version
libprotoc 3.19.4
小結
使用 homebrew 安裝指定版本的其他軟件也是類似的操作,希望能幫助到大家。