Protocol Buffer Compiler Installation

How to install the protocol buffer compiler.

The protocol buffer compiler, protoc, is used to compile .proto files, which contain service and message definitions. Choose one of the methods given below to install protoc.

Install Pre-compiled Binaries (Any OS)

To install the latest release of the protocol compiler from pre-compiled binaries, follow these instructions:

  1. Navigate to the latest GitHub Release.

  2. Download the zip file corresponding to your operating system and computer architecture (protoc-<version>-<os>-<arch>.zip).

    • For example, for Linux x86-64 on 34.1, the filename would be protoc-34.1-linux-x86_64.zip.

    Alternative: Download using commands

    Instead of manual download, you can use the following commands to automatically fetch the latest Linux x86_64 asset:

    # Fetch the download URL for the latest Linux x86_64 asset from GitHub API
    URL=$(curl -s https://api.github.com/repos/protocolbuffers/protobuf/releases/latest \
      | jq -r '.assets[] | select(.name | endswith("linux-x86_64.zip")) | .browser_download_url')
    curl -LO $URL
    
  3. Unzip the file under $HOME/.local or a directory of your choice. For example:

    # If you used the command above:
    unzip $(basename $URL) -d $HOME/.local
    
    # If you downloaded manually (replace <version> with actual version):
    # unzip protoc-<version>-linux-x86_64.zip -d $HOME/.local
    
  4. Update your environment’s path variable to include the path to the protoc executable. For example:

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

Install Using a Package Manager

You can install the protocol compiler, protoc, with a package manager under Linux, macOS, or Windows using the following commands.

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

    apt install -y protobuf-compiler
    protoc --version  # Ensure compiler version is 33.0+
    
  • MacOS, using Homebrew:

    brew install protobuf
    protoc --version  # Ensure compiler version is 33.0+
    
  • Windows, using Winget

    > winget install protobuf
    > protoc --version # Ensure compiler version is 33.0+
    

Other Installation Options

If you’d like to build the protocol compiler from sources, or access older versions of the pre-compiled binaries, see Download Protocol Buffers.