|
| 1 | +# Installing protoc |
| 2 | + |
| 3 | +Learn how to install `protoc`, the Protocol Buffers compiler. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Protocol Buffers compiler is a command line tool for generating source code from `.proto` |
| 8 | +files and is required to generate gRPC stubs and messages. You can learn more about it on the |
| 9 | +[Protocol Buffers website](https://protobuf.dev/). |
| 10 | + |
| 11 | +You can install `protoc` in a number of ways including: |
| 12 | + |
| 13 | +1. Via a package manager, |
| 14 | +2. By downloading the binary. |
| 15 | + |
| 16 | +### Install via a package manager |
| 17 | + |
| 18 | +Using a package manager is the easiest way to install `protoc`. |
| 19 | + |
| 20 | +On macOS you can use [Homebrew](https://brew.sh): |
| 21 | + |
| 22 | +```sh |
| 23 | +brew install protobuf |
| 24 | +``` |
| 25 | + |
| 26 | +On Ubuntu and Debian you can use `apt`: |
| 27 | + |
| 28 | +```sh |
| 29 | +apt update && apt install -y protobuf-compiler |
| 30 | +``` |
| 31 | + |
| 32 | +On Fedora you can use `dnf`: |
| 33 | + |
| 34 | +```sh |
| 35 | +dnf install -y protobuf-compiler |
| 36 | +``` |
| 37 | + |
| 38 | +### Installing a pre-built binary |
| 39 | + |
| 40 | +If you're unable to use a package manager to install `protoc` then you may be able |
| 41 | +to download a pre-built binary from the [Protocol Buffers GitHub |
| 42 | +repository](https://github.com/protocolbuffers/protobuf). |
| 43 | + |
| 44 | +First, find and download the appropriate binary for your system from the |
| 45 | + [releases](https://github.com/protocolbuffers/protobuf/releases) page. |
| 46 | + |
| 47 | +Next, unzip the artifact to a directory called `protoc`: |
| 48 | + |
| 49 | +```sh |
| 50 | +unzip /path/to/downloaded/protoc-{VERSION}-{OS}.zip -d protoc |
| 51 | +``` |
| 52 | + |
| 53 | +Finally, move `protoc/bin/protoc` to somewhere in your `$PATH` such as `/usr/local/bin`: |
| 54 | + |
| 55 | +```sh |
| 56 | +mv protoc/bin/protoc /usr/local/bin |
| 57 | +``` |
| 58 | + |
| 59 | +You can now remove the `protoc` directory. |
0 commit comments