How to Install Protocol Buffers Compiler on macOS and Linux (2025)
How to Install Protocol Buffers Compiler on macOS and Linux (2025)
Protocol Buffers (protobuf) is Google's language-neutral serialization format, widely used in microservices, gRPC applications, and distributed systems. Before you can use protobuf in your projects, you need to install two components: the protocol compiler (protoc) and the runtime library for your specific programming language.
This guide walks you through installing protobuf on macOS and Linux systems, covering pre-built binaries, package managers, and source compilation.
Why You Need Protobuf Installation
When working with Protocol Buffers, your development workflow requires:
- protoc compiler – Converts
.protoschema files into generated code for your language - Runtime libraries – Handles serialization/deserialization at runtime
- Development headers – Required for C++ and some other language bindings
Skipping proper installation leads to protoc: command not found errors or missing runtime dependencies that only surface in production.
Method 1: Install Using Pre-Built Binaries (Fastest)
The easiest approach for most developers is downloading pre-built binaries from the official GitHub releases page.
On macOS (Intel and Apple Silicon)
- Visit https://github.com/protocolbuffers/protobuf/releases
- Find the latest release and download
protoc-X.X.X-osx-x86_64.zip(Intel) orprotoc-X.X.X-osx-aarch_64.zip(Apple Silicon) - Extract the archive:
unzip protoc-27.0-osx-x86_64.zip -d protoc-install
- Move the binary to your PATH:
sudo mv protoc-install/bin/protoc /usr/local/bin/
sudo mv protoc-install/include/google /usr/local/include/
rm -rf protoc-install
- Verify installation:
protoc --version
# Output: libprotoc 27.0
On Linux (Ubuntu/Debian)
- Download the appropriate Linux binary from releases (e.g.,
protoc-27.0-linux-x86_64.zip) - Extract and install:
unzip protoc-27.0-linux-x86_64.zip -d protoc-install
sudo mv protoc-install/bin/protoc /usr/local/bin/
sudo mv protoc-install/include/google /usr/local/include/
rm -rf protoc-install
protoc --version
On Linux (Using Package Manager)
For Ubuntu/Debian-based systems, protobuf is available in standard repositories:
sudo apt-get update
sudo apt-get install protobuf-compiler
protoc --version
For Fedora/RHEL-based systems:
sudo dnf install protobuf-compiler
Method 2: Installing Language-Specific Runtime Libraries
After installing protoc, you must install the runtime library for your language.
Python
Use pip to install the protobuf Python package:
pip install protobuf==4.24.0
Verify in a Python shell:
import google.protobuf
print(google.protobuf.__version__)
Go
Install the Go protocol buffers library:
go get -u google.golang.org/protobuf@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
Node.js
For JavaScript/TypeScript projects:
npm install google-protobuf
# Or for TypeScript support:
npm install protobufjs
Java
For Maven projects, add to pom.xml:
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>4.24.0</version>
</dependency>
Method 3: Building from Source (For C++ Users)
If you're using C++ or need to build protobuf as part of your project, compile from source:
Prerequisites (macOS with Homebrew)
brew install autoconf automake libtool
Prerequisites (Ubuntu/Debian)
sudo apt-get install autoconf automake libtool curl g++ unzip
Build and Install
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig
protoc --version
This approach is more time-consuming but necessary if you're modifying protobuf internals or using the latest development version.
Using Protobuf with Bazel (Build Systems)
If your project uses Bazel, add protobuf as a dependency in your MODULE.bazel:
bazel_dep(name = "protobuf", version = "27.0")
For legacy WORKSPACE files:
http_archive(
name = "com_google_protobuf",
sha256 = "...",
strip_prefix = "protobuf-27.0",
url = "https://github.com/protocolbuffers/protobuf/archive/v27.0.tar.gz",
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
Installation Troubleshooting
Error: "protoc: command not found"
The binary isn't in your PATH. Check your installation:
which protoc
# If empty, the binary isn't installed
Re-run the installation steps and ensure /usr/local/bin is in your PATH:
echo $PATH
Error: "Cannot find google/protobuf headers"
The include files weren't installed. Ensure you copied the include/google directory to /usr/local/include/:
ls /usr/local/include/google/protobuf/
Version Conflicts Between protoc and Runtime
Keep versions aligned. If protoc is version 27.0, install the same version of runtime libraries:
protoc --version # Check compiler version
pip list | grep protobuf # Check Python runtime version
Verification: Compile Your First .proto File
Create a simple example to confirm everything works:
cat > example.proto << 'EOF'
syntax = "proto3";
message Person {
string name = 1;
int32 id = 2;
string email = 3;
}
EOF
protoc --python_out=. example.proto
ls example_pb2.py # Generated Python file
If example_pb2.py appears, your installation is complete.
Keeping Protobuf Updated
Monitor the official releases page for security updates and new features. Update using the same method you installed:
- Package manager:
apt-get upgrade protobuf-compiler - Pre-built binaries: Download newer version and replace binary
- Python runtime:
pip install --upgrade protobuf - Language runtimes: Follow language-specific upgrade paths
Conclusion
Installing Protocol Buffers correctly ensures smooth development with modern serialization formats. For most developers, the pre-built binary method is fastest, while package managers work well for system-wide installations. Language-specific runtimes must match your protoc compiler version to avoid serialization mismatches in production systems.