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:
Update your .bashrc or .zshrc file:
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
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
This will download and install the latest versions of the necessary plugins.
Generate the Go code:
protoc --go-grpc_out=. *.proto
This will generate the Go code needed for your gRPC application.
Additional Notes:
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!