avatar

目录
安装指定版本的 protoc

由于前几天升级了protoc的版本用于新项目,导致老项目的protoc版本不一致,偏偏这个老项目的protoc版本不能升级,所以需要安装指定版本的protoc。

但当去执行brew install protoc@v3.21.9的时候,提醒我这个版本已经不支持了。

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
brew install protoc@v3.21.9
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 4 taps (shivammathur/php, homebrew/services, homebrew/core and homebrew/cask).
==> New Formulae
cargo-sweep chisel-tunnel direwolf glbinding@2 redress
==> New Casks
garmin-basecamp reader truhu

You have 36 outdated formulae installed.

Warning: No available formula with the name "protoc@v3.21.9". Did you mean protobuf@21?
==> Searching for similarly named formulae and casks...
==> Formulae
protobuf@21 ✔

To install protobuf@21 ✔, run:
brew install protobuf@21 ✔

后面找了很多方法,要么卸载后重新下载,走压缩安装的方式,哎我还就不信了,homebrew的方式不行吗?捣鼓了半天发现是可以的。

首先找到对应的要安装的链接,使用brew info protobuf

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Protocol buffers (Google's data interchange format)
https://protobuf.dev/
/opt/homebrew/Cellar/protobuf/25.1 (458 files, 14.7MB) *
Poured from bottle using the formulae.brew.sh API on 2023-12-08 at 17:15:54
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/p/protobuf.rb
License: BSD-3-Clause
==> Dependencies
Build: cmake ✘, python-setuptools ✘, python@3.11 ✔, python@3.12 ✘
Required: abseil ✔, jsoncpp ✔
==> Caveats
Emacs Lisp files have been installed to:
/opt/homebrew/share/emacs/site-lisp/protobuf
==> Analytics
install: 60,227 (30 days), 177,592 (90 days), 498,980 (365 days)
install-on-request: 29,124 (30 days), 83,154 (90 days), 229,480 (365 days)
build-error: 14 (30 days)

拿到protobuf.rb 的地址为 https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/protobuf.rb, 找到history,选择自己需要的版本。
把文件保存到本地。命名为protobuf.rb

然后执行brew install ./protobuf.rb,就可以安装指定版本的protoc了。如果有冲突,记得将已安装的高版本的protoc卸载掉。


文章作者: Viola Tangxl
文章链接: https://violatangxl.github.io/2023/12/14/brew-install-protoc-version/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 椰子是只猫
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论