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

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

Barbara Streisand
Release: 2024-12-09 22:27:24
Original
577 people have browsed it

How to Fix the

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

While attempting to generate Go code for a gRPC application, you may encounter the error "protoc-gen-go: program not found or is not executable." This issue can arise due to using an outdated approach in Go 1.17 and later versions.

Solution for Go 1.17

In Go 1.17, installing executables using go get has been deprecated in favor of go install. To resolve this error for Go 1.17 and later versions, follow these steps:

  1. Update your .bashrc or .zshrc file:

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

    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

    This will download and install the latest versions of the necessary plugins.

  3. Generate the Go code:

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

    This will generate the Go code needed for your gRPC application.

Additional Notes:

  • Ensure you have the protoc compiler installed and available in your PATH.
  • Restart your terminal or command line after making changes to your .bashrc or .zshrc file.
  • Consult the official Go documentation for the most up-to-date information on installing and using these plugins.

The above is the detailed content of How to Fix the 'protoc-gen-go: program not found or is not executable' Error in Go gRPC?. 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