How to Fix protoc-gen-go-grpc: program not found or is not executable

Error protoc-gen-go-grpc: program not found or is not executable occurs in Go you try to “generate Go gRPC code using the protoc tool, but the required plugin protoc-gen-go-grpc is not installed or not in the system’s PATH.”

Diagram of error and its solution

protoc-gen-go-grpc_ program not found or is not executable

How to fix the error?

To fix the protoc-gen-go-grpc: program not found or is not executable error in Go, install the protoc-gen-go-grpc plugin using this command: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest. This command will download and install the protoc-gen-go-grpc plugin into your GOBIN or GOPATH/bin directory.

Starting in Go 1.17, installing executables with “go get” has been deprecated. That’s why I used “go install.”

After installing the plugin, follow these steps:

  1. Ensure that your GOBIN or GOPATH/bin directory is added to your system’s PATH environment variable. This allows the protoc compiler to find and use the protoc-gen-go-grpc plugin.
  2. Add the following line to your ~/.bashrc, ~/.bash_profile, or ~/.zshrc file (depending on your shell):
    export PATH=$PATH:$(go env GOPATH)/bin
    
  3. After adding this line, restart your terminal or run source ~/.bashrc, source ~/.bash_profile, or source ~/.zshrc to apply the changes.

Now the protoc compiler should be able to find and use the protoc-gen-go-grpc plugin when generating the gRPC code for Go. This is a one-stop solution, as I fixed the error myself, and it will work for you as well.

If you are using Linux, you can download the package using this command:

sudo apt install golang-goprotobuf-dev

That’s it.

1 thought on “How to Fix protoc-gen-go-grpc: program not found or is not executable”

Comments are closed.