|
| 1 | ++++ |
| 2 | +title = "Protocol Buffer Compiler Installation" |
| 3 | +weight = 15 |
| 4 | +description = "How to install the protocol buffer compiler." |
| 5 | +type = "docs" |
| 6 | +no_list = "true" |
| 7 | +linkTitle = "Protoc Installation" |
| 8 | ++++ |
| 9 | + |
| 10 | +The protocol buffer compiler, `protoc`, is used to compile `.proto` files, which |
| 11 | +contain service and message definitions. Choose one of the methods given below |
| 12 | +to install `protoc`. |
| 13 | + |
| 14 | +### Install Pre-compiled Binaries (Any OS) {#binary-install} |
| 15 | + |
| 16 | +To install the latest release of the protocol compiler from pre-compiled |
| 17 | +binaries, follow these instructions: |
| 18 | + |
| 19 | +1. From https://github.com/google/protobuf/releases, manually download the zip |
| 20 | + file corresponding to your operating system and computer architecture |
| 21 | + (`protoc-<version>-<os>-<arch>.zip`), or fetch the file using commands such |
| 22 | + as the following: |
| 23 | + |
| 24 | + ```sh |
| 25 | + PB_REL="https://github.com/protocolbuffers/protobuf/releases" |
| 26 | + curl -LO $PB_REL/download/v< param protoc-version >/protoc-< param protoc-version >-linux-x86_64.zip |
| 27 | + ``` |
| 28 | + |
| 29 | +2. Unzip the file under `$HOME/.local` or a directory of your choice. For |
| 30 | + example: |
| 31 | + |
| 32 | + ```sh |
| 33 | + unzip protoc-< param protoc-version >-linux-x86_64.zip -d $HOME/.local |
| 34 | + ``` |
| 35 | + |
| 36 | +3. Update your environment's path variable to include the path to the `protoc` |
| 37 | + executable. For example: |
| 38 | +
|
| 39 | + ```sh |
| 40 | + export PATH="$PATH:$HOME/.local/bin" |
| 41 | + ``` |
| 42 | +
|
| 43 | +### Install Using a Package Manager {#package-manager} |
| 44 | +
|
| 45 | +{{% alert title="Warning" color="warning" %}} Run |
| 46 | +`protoc --version` to check the version of `protoc` after using a package |
| 47 | +manager for installation to ensure that it is sufficiently recent. The versions |
| 48 | +of `protoc` installed by some package managers can be quite dated. See the |
| 49 | +[Version Support page](https://protobuf.dev/support/version-support) to compare |
| 50 | +the output of the version check to the minor version number of the supported |
| 51 | +version of the language(s) you are |
| 52 | +using.{{% /alert %}} |
| 53 | +
|
| 54 | +You can install the protocol compiler, `protoc`, with a package manager under |
| 55 | +Linux, macOS, or Windows using the following commands. |
| 56 | +
|
| 57 | +- Linux, using `apt` or `apt-get`, for example: |
| 58 | +
|
| 59 | + ```sh |
| 60 | + apt install -y protobuf-compiler |
| 61 | + protoc --version # Ensure compiler version is 3+ |
| 62 | + ``` |
| 63 | +
|
| 64 | +- MacOS, using [Homebrew](https://brew.sh): |
| 65 | +
|
| 66 | + ```sh |
| 67 | + brew install protobuf |
| 68 | + protoc --version # Ensure compiler version is 3+ |
| 69 | + ``` |
| 70 | +
|
| 71 | +- Windows, using |
| 72 | + [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/) |
| 73 | +
|
| 74 | + ```sh |
| 75 | + > winget install protobuf |
| 76 | + > protoc --version # Ensure compiler version is 3+ |
| 77 | + ``` |
| 78 | +
|
| 79 | +### Other Installation Options {#other} |
| 80 | +
|
| 81 | +If you'd like to build the protocol compiler from sources, or access older |
| 82 | +versions of the pre-compiled binaries, see |
| 83 | +[Download Protocol Buffers](https://protobuf.dev/downloads). |
0 commit comments