Protocol Buffer 编译器安装
如何安装 protocol buffer 编译器。
protocol buffer 编译器 protoc
用于编译包含服务和消息定义的 .proto
文件。选择下面提供的一种方法来安装 protoc
。
安装预编译二进制文件 (任何操作系统)
要从预编译的二进制文件安装最新版本的 protocol 编译器,请按照以下说明操作
从 https://github.com/google/protobuf/releases 手动下载与您的操作系统和计算机架构对应的 zip 文件(
protoc-<version>-<os>-<arch>.zip
),或者使用以下命令获取文件PB_REL="https://github.com/protocolbuffers/protobuf/releases" curl -LO $PB_REL/download/v30.2/protoc-30.2-linux-x86_64.zip
将文件解压到
$HOME/.local
或您选择的目录。例如unzip protoc-30.2-linux-x86_64.zip -d $HOME/.local
更新您的环境变量 PATH,使其包含
protoc
可执行文件的路径。例如export PATH="$PATH:$HOME/.local/bin"
使用包管理器安装
警告
在使用包管理器安装后运行protoc --version
检查 protoc
的版本,以确保其足够新。一些包管理器安装的 protoc
版本可能相当陈旧。请参阅版本支持页面,将版本检查的输出与您使用的语言支持的次要版本号进行比较。您可以使用包管理器在 Linux、macOS 或 Windows 下安装 protocol 编译器 protoc
,使用以下命令。
Linux,例如使用
apt
或apt-get
apt install -y protobuf-compiler protoc --version # Ensure compiler version is 3+
MacOS,使用 Homebrew
brew install protobuf protoc --version # Ensure compiler version is 3+
Windows,使用 Winget
> winget install protobuf > protoc --version # Ensure compiler version is 3+
其他安装选项
如果您想从源代码构建 protocol 编译器,或访问较旧版本的预编译二进制文件,请参阅下载 Protocol Buffers。