protoc & protoc-gen-go安装

[!TIP] This document is machine-translated by Google. If you find grammatical and semantic errors, and the document description is not clear, please PR


protoc is a tool written in C++, which can translate proto files into codes in the specified language. In the go-zero microservices, we use grpc to communicate between services, and the writing of grpc requires the use of protoc and the plug-in protoc-gen-go that translates into go language rpc stub code.

Demonstration environment of this document

  • mac OS
  • protoc 3.14.0

protoc installation

  • Enter the protobuf release page and select the compressed package file suitable for your operating system
  • Unzip and enter protoc-3.14.0-osx-x86_64
      $ cd protoc-3.14.0-osx-x86_64/bin
  • Move the started protoc binary file to any path added to the environment variable, such as $GOPATH/bin. It is not recommended putting it directly with the next path of the system.
      $ mv protoc $GOPATH/bin

    [!TIP] $GOPATH is the actual folder address of your local machine

  • Verify the installation result
      $ protoc --version
      libprotoc 3.14.0

    protoc-gen-* installation


Windows may report an error, A required privilege is not held by the client., because goctl needs to be run as administrator under Windows. The reason is that goctl needs to be run "as administrator" under Windows.

  • Download and install protoc-gen-go

If the goctl version is already 1.2.1 or later, you can ignore this step.

$ go get -u
go: found in v1.4.3
go: upgrade => v1.25.0
  • Move protoc-gen-go to any path where environment variables are added, such as $GOPATH/bin, because the binary itself after go get is in the $GOPATH/bin directory, so just make sure your $GOPATH/bin can be in the environment variable.

**[!WARNING] protoc-gen-go installation failed, please read Error

Copyright © 2019-2021 go-zero all right reserved,powered by GitbookLast UpdateTime: 2021-12-05 09:48:50

results matching ""

    No results matching ""