--go-grpc_out: protoc-gen-go-grpc: Plugin failed with status code 1
Asked Answered
A

1

8

i am getting this error when i compile my proto file:

protoc-gen-go-grpc: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
\--go-grpc_out: protoc-gen-go-grpc: Plugin failed with status code 1.

I am using these versions:

Binary Version
protoc-gen-go v1.25.0-devel
protoc v3.12.4

I have tried to compile this proto file:

syntax = "proto3";

option go_package = "proto/";

message GreetingRequest {
  string first_name = 1;
  string last_name = 2;
}
message GreetingResponse{
  string result = 1;
}

service AddService{
  rpc Greet(GreetingRequest) returns (GreetingResponse) {};
}

I used this command:

protoc \
--proto_path=proto \
--go_out=proto \
--go_opt=paths=source_relative \
--go-grpc_out=proto \
--go-grpc_opt=paths=source_relative \
service.proto

I installed protoc-gen-go-grpc using:

go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

but its still showing this error.

Adrenocorticotropic answered 1/4, 2022 at 12:42 Comment(6)
Thank you for the clear repro of your issue. Are you running on Linux? If so, please try which protoc-gen-go-grpc to determine where (in your path), the binary can be found. I suspect, it won't be found and you'll need to add it's location to your PATHEmerald
For me, the file is in ${GOPATH}/bin. You may not have GOPATH (and I think there's a GOBIN) too.Emerald
When you run protoc, it looks for plugins (other binaries) in the PATH on your system. In your case, there are 2 plugins that are used. --go_* is matched to a binary protoc-gen-go and --go-grpc_* is matched to a binary protoc-gen-go-grpc. The flags are used to determine the binary's name protoc-gen-[[FLAG]]. You just need to ensure that both those binaries are in the PATH so that protoc can find them when you run it.Emerald
Thank you for helping. Right after installing protoc-gen-go-grpc I have used following command to set path: export PATH="$PATH:$(go env GOPATH)/bin" which sets the path to: /home/zohaib/go/bin/protoc-gen-go-grpc but the path should be: /usr/bin where protoc-gen-go lies.Adrenocorticotropic
I'm unsure whether your comment was a statement of a question. To reiterate, you need to set the PATH to include whatever paths you're using so that protoc can find protoc-gen-go and protoc-gen-go-gprc in the PATH. If these are in different locations both folders need to be in the PATH.Emerald
Found a temporary solution to the problem, everytime before compiling my proto file I have to explicitly set path of protoc-gen-go-grpc in the terminal using: PATH="/myDirectory:$PATH". Now the problem is how to set this path permanently?Adrenocorticotropic
P
3

Hello if you are running on mac m1 try using this command

export PATH="$PATH:$(go env GOPATH)/bin"

to make this change permanent you may have to modify your ~/.zshrc file and source it

got it from here

https://grpc.io/docs/languages/go/quickstart/

Periapt answered 9/3, 2023 at 12:7 Comment(1)
This actually was my issue, thanks for that.Salters

© 2022 - 2025 — McMap. All rights reserved.