How to Install Protocol Buffer Compiler

How to install the protocol buffer compiler.

Although not mandatory, Apache Dubbo supports using Protocol Buffers (proto3) for service definitions and serialization protocols.

Within the protocol buffer framework, we use .proto files to define services and message body formats, and the protoc compiler to compile .proto files. You can install protoc in the following ways.

Installing via Package Manager

On Linux or macOS, you can use a package manager to install protoc.

  • Linux, using apt or apt-get, for example:

    $ apt install -y protobuf-compiler
    $ protoc --version  # Ensure compiler version is 3+
    
  • macOS, using Homebrew:

    $ brew install protobuf
    $ protoc --version  # Ensure compiler version is 3+
    

Binary Installation (for any OS)

Follow these steps to install the latest version of the protoc binary package:

  1. Manually download the binary files for your OS from github.com/google/protobuf/releases (protoc-<version>-<os>-<arch>.zip), or use the following commands to download directly:

    $ PB_REL="https://github.com/protocolbuffers/protobuf/releases"
    $ curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
    
  2. Unzip the file to the $HOME/.local directory, or any directory of your choice. For example:

    $ unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
    
  3. Modify the system PATH to include the protoc executable. For example:

    $ export PATH="$PATH:$HOME/.local/bin"
    

Other Installation Methods

If you want to compile from the source yourself, or if you want to install an older version of the binary package, please refer to Download Protocol Buffers

Last modified September 30, 2024: Replace addr (aaa3d67237)