Install protoc on Ubuntu 22.04

Install protoc on Ubuntu 22.04

Protocol buffers also known as protobuf is a cross-platform data format for serializing structured data. The protoc is a protocol buffer compiler used to compile .proto files which describes message and service definitions.

This tutorial explains how to install protoc on Ubuntu 22.04.

Prepare environment

Make sure you have installed unzip package for extracting protoc executable file from a ZIP archive.

sudo apt update
sudo apt install -y unzip

Install protoc

Get the latest version tag of protoc release and assign it to variable:

PROTOC_VERSION=$(curl -s "" | grep -Po '"tag_name": "v\K[0-9.]+')

Download ZIP archive from releases page of the protoc repository:

curl -Lo "${PROTOC_VERSION}"

Run the following command to extract the executable file from a ZIP archive:

sudo unzip -q bin/protoc -d /usr/local

Set execute permission:

sudo chmod a+x /usr/local/bin/protoc

Now the protoc command is available for all users as a system-wide command.

We can check protoc version:

protoc --version

Remove unnecessary ZIP archive:

rm -rf

Testing protoc

Create .proto file:

nano example.proto

Add the following code, which defines simple message format:

syntax = "proto3";

package example;

message Person {
  string name = 1;

Once you have the .proto file, you need to compile it with the protoc compiler. It will parse the .proto file and will generate source files according to specified programming language. For example, the following command generates the file in current working directory:

protoc --python_out=. example.proto

Generated file for specific language is like a template which can be used to provide the data based on defined structure for serialization.

Uninstall protoc

If you decided to completely remove protoc, delete executable file:

sudo rm -rf /usr/local/bin/protoc

For environment preparation, we needed to install unzip package. You can remove it:

sudo apt purge --autoremove -y unzip

The 3 Comments Found

    • Avatar
      lindevs Reply

      The protoc available through APT package manager could be outdated. The installation guide provided in the post explains how to install the latest version of protoc.

Leave a Comment

Cancel reply

Your email address will not be published.