Home > Backend Development > Golang > How to Fix the 'protoc-gen-go: program not found or is not executable' Error in Go?

How to Fix the 'protoc-gen-go: program not found or is not executable' Error in Go?

Barbara Streisand
Release: 2024-12-04 17:30:12
Original
940 people have browsed it

How to Fix the

Resolving "protoc-gen-go: program not found or is not executable" Error in Go gRPC Projects

When attempting to generate code for a gRPC application in Go, users may encounter the "protoc-gen-go: program not found or is not executable" error. This issue arises because the protoc-gen-go plugin, a crucial component for code generation, is either absent or inaccessible.

Solution:

For Go versions 1.17 and above, the following steps should resolve the issue:

  1. Update Installation Method: As of Go 1.17, using go get to install executables is deprecated. Use go install instead.
  2. Set Environment Variables: Configure the GOPATH and PATH environment variables as follows:

    • ~/.bashrc

      export GOPATH=$HOME/go
      export PATH=$PATH:$GOPATH/bin
      Copy after login
  3. Install Plugins: Install the protoc-gen-go and protoc-gen-go-grpc plugins using:

    go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
    
    go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
    Copy after login
  4. Generate Code: Once the plugins are installed, use the following command to generate the code:

    protoc --go-grpc_out=. *.proto
    Copy after login

By following these steps, you should be able to successfully generate code for your gRPC application in Go. Ensure that your environment variables are set correctly and that the necessary plugins are installed.

The above is the detailed content of How to Fix the 'protoc-gen-go: program not found or is not executable' Error in Go?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template