Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to build a sample application with Go gRPC, but I am unable to generate the code using "protoc"

I have installed the required libraries and Go packages using:

  1. go get -u google.golang.org/grpc
  2. go get -u github.com/golang/protobuf/protoc-gen-go

I have tried setting the path as well, but no luck.

Sample "proto" file:

syntax = "proto3";

package greet;
option go_package="greetpb";

service GreetService{}

Error message:

"protoc-gen-go: program not found or is not executable
--go_out: protoc-gen-go: Plugin failed with status code 1."

like image 463
Mayank Gupta Avatar asked Aug 28 '19 22:08

Mayank Gupta


People also ask

How do you install protoc GEN go in Windows?

Download protoc-win32. zip from https://developers.google.com/protocol-buffers/docs/downloads. Unzip and add location of the protoc.exe to your PATH environment variable. Run `protoc --version` from command prompt to verify.

How do I run protoc Gen?

Using protocol buffers with Go To compile the protocol buffer definition, run protoc with the --go_out parameter set to the directory you want to output the Go code to. The generated files will be suffixed . pb.go. See the Test code below for an example using such a file.


3 Answers

There are two ways to install the protobuf compiler. If you're on Ubuntu you can use this:

sudo apt install protobuf-compiler 

Then of course there's the standard way:

go get -u github.com/golang/protobuf/{proto,protoc-gen-go} 

Here forward it's just adding the path. Assuming when you installed Go you did this,

echo 'export GOPATH=$HOME/Go' >> $HOME/.bashrc source $HOME/.bashrc 

Now you can just extend this:

echo 'export PATH=$PATH:$GOPATH/bin' >> $HOME/.bashrc source $HOME/.bashrc 

Strangely protoc can't expand ~.

like image 123
Tannisha Hill Avatar answered Sep 22 '22 18:09

Tannisha Hill


Tannisha Hill indicated that the following package had to be added:

sudo apt install protobuf-compiler

In my case, I also had to add this one:

sudo apt install golang-goprotobuf-dev
like image 40
Panchove Avatar answered Oct 21 '22 07:10

Panchove


I resolved it by following these steps:

Install the Go library using:

go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
  1. Run vim ~/.bash_profile
  2. Add:
    export GO_PATH=~/go
    export PATH=$PATH:/$GO_PATH/bin
    
  3. Run source ~/.bash_profile

Reference: Unable to build protobuf to go endpoint

like image 34
Mayank Gupta Avatar answered Oct 21 '22 06:10

Mayank Gupta