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

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

Susan Sarandon
Release: 2024-12-09 11:52:12
Original
541 people have browsed it

How to Fix the

Generating gRPC Code: Resolving "protoc-gen-go: program not found or is not executable" Error

In attempting to build a gRPC application with Go, users may encounter difficulties when generating code using the "protoc" command. This error message, "protoc-gen-go: program not found or is not executable," indicates that the necessary tools are missing or not configured correctly.

Resolution for Go 1.17

Recent versions of Go have deprecated the use of "go get" for installing executables. Instead, use "go install" as recommended in the official documentation.

  1. Update .bashrc:

    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    Copy after login
  2. Install Tools:

    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
  3. Generate Code:

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

Additional Notes:

  • Ensure that the "go" command points to the correct Go installation.
  • If the error persists, try setting the path to the "protoc-gen-go" executable explicitly.
  • Consult the Go documentation for additional information on managing packages and tools: https://go.dev/doc/go-get-install-deprecation

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