Unable to build protobuf to go endpoint
Solution 1:
protoc-gen-go
needs to be in your shell path, i.e. one of the directories listed in the PATH
environment variable, which is different from the Go path. You can test this by simply typing protoc-gen-go
at the command line: If it says "command not found" (or similar) then it's not in your PATH
.
Solution 2:
Using
$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
is more safe than using
$ sudo apt-get install golang-goprotobuf-dev
Because the latest protoc-gen-go
is using the lib github.com/golang/protobuf/proto
, but protoc-gen-go
in apt-get
using the lib code.google.com/p/goprotobuf/proto
which didn't exist now.
Solution 3:
You should properly define your
GO_PATH
- where your go packages live. In other words,GO_PATH
is your go workspace. TheGO_PATH
should be~/go
.protoc-gen-go
should be in yourPATH
. Whileprotoc-gen-go
lives in$GO_PATH/bin
after you installed it.
Add these 2 important lines to your ~/.bash_profile
:
export GO_PATH=~/go
export PATH=$PATH:/$GO_PATH/bin
Then you need to start a new shell session or just type in this line:
$ source ~/.bash_profile
Solution 4:
On Ubuntu 18.04, this is verified working to solve this issue:
sudo apt-get install golang-goprotobuf-dev
Solution 5:
I have Ubuntu 18.04.02 LTS and installed protoc
using
sudo apt install protobuf-compiler
I have my GOPATH and GOBIN set correctly, but still when I did a
protoc --go_out=. <filename>
I was getting
protoc-gen-go: program not found or is not executable
--go_out: protoc-gen-go: Plugin failed with status code 1.
After reading bunch of places, was able to find that doing
go get -u github.com/golang/protobuf/protoc-gen-go
was able to fix the issue. Hope this helps someone out there.