The protoc compiler is the gatekeeper for your Protocol Buffers, translating human-readable .proto files into language-specific code that your applications can use.

Let’s get it installed.

On macOS (using Homebrew)

If you’re on macOS and use Homebrew, this is your quickest route.

brew install protobuf

This command fetches the latest stable version of Protocol Buffers, including protoc, from Homebrew’s repositories and installs it into your system’s PATH. You’ll find the protoc executable in /usr/local/bin/protoc (or /opt/homebrew/bin/protoc on Apple Silicon).

To verify, run:

protoc --version

You should see output like libprotoc 3.21.7.

On Debian/Ubuntu Linux

For Debian-based Linux distributions, apt is your friend.

sudo apt update
sudo apt install protobuf-compiler

The apt update ensures your package list is current, and protobuf-compiler installs the protoc binary. It’ll typically land in /usr/bin/protoc.

Check the version with:

protoc --version

Expected output: libprotoc 3.18.1 (the version might differ based on your distribution’s repositories).

On Fedora/CentOS/RHEL Linux

Red Hat-based systems use dnf or yum.

sudo dnf install protobuf-compiler

Or, if you’re on an older system:

sudo yum install protobuf-compiler

This installs the protoc compiler, usually found at /usr/bin/protoc.

Verify with:

protoc --version

Output will be similar to libprotoc 3.18.1.

From Source (Advanced/Cross-Platform)

If your distribution’s package manager doesn’t have a recent version, or you need to compile for a specific environment, building from source is the way to go. This is a more involved process but gives you maximum control.

  1. Install Dependencies: You’ll need a C++ compiler (like g++ or clang), make, and cmake. On Debian/Ubuntu:

    sudo apt update
    sudo apt install build-essential cmake
    

    On macOS: Xcode Command Line Tools (install with xcode-select --install).

  2. Download Source: Get the latest release from the Protocol Buffers GitHub releases page. For example, if the latest is v21.12:

    wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protobuf-all-21.12.tar.gz
    tar -zxvf protobuf-all-21.12.tar.gz
    cd protobuf-21.12
    
  3. Compile and Install:

    ./configure
    make
    sudo make install
    

    The ./configure script checks your system for necessary components. make compiles the code, and make install places the binaries, libraries, and header files in standard system locations. protoc will typically be installed in /usr/local/bin/protoc.

    Note: You might need to run sudo ldconfig on Linux after installation if you encounter library path issues.

  4. Verify:

    protoc --version
    

    This should show the version you just compiled, e.g., libprotoc 21.12.0.

Windows

On Windows, the easiest method is often using a package manager like Chocolatey or Scoop.

Using Chocolatey:

choco install protoc

This installs protoc and adds it to your system’s PATH.

Using Scoop:

scoop install protoc

This also handles adding protoc to your PATH.

After installation via either method, open a new Command Prompt or PowerShell window and run:

protoc --version

You’ll see the installed version, like libprotoc 3.21.7.

The Next Step: Compiling Your First .proto File

Once protoc is installed, the next logical step is to use it to generate code for your specific programming language. For example, to generate a Python class from a message.proto file:

protoc --python_out=. message.proto

This command tells protoc to compile message.proto and place the generated Python code (e.g., message_pb2.py) in the current directory (.). You’ll then import this generated file into your Python application.

Want structured learning?

Take the full Protobuf course →