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

Mayank Gupta picture Mayank Gupta · Aug 29, 2019 · Viewed 15.4k times · Source

I am trying to build a sample app with go grpc but I am unable to generate the code using "protoc"

Have installed the required libraries/go packages using:

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

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."

Answer

Tannisha Hill picture Tannisha Hill · Aug 30, 2019

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 ~.