74

using protobuf version 2.6.1 ( which i installed via homebrew)

I am trying to run

$ protoc --go_out=../cloud/ *.proto

I keep receiving this error.

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

I have the protoc-gen-go installed in my go path. Anyone else have this issue?

R.J. Robinson
  • 2,180
  • 3
  • 21
  • 33
  • 5
    Try manually installing based on the instructions here: https://github.com/golang/protobuf `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}`. There may be something wrong with the homebrew install. – Intermernet Jan 22 '15 at 22:00
  • Reinstalled everything. still the same error. I switched over to ver 2.6.0 . Still the same error. – R.J. Robinson Jan 23 '15 at 00:26
  • 2
    You say `protoc-gen-go` is in your "go path", but it needs to be in your shell path, i.e. one of the directories listed in the `PATH` environment variable. What happens if you just type `protoc-gen-go` at the command line? If it says "command not found" (or similar) then it's not in your `PATH`. – Kenton Varda Jan 23 '15 at 03:26
  • Thanks @KentonVarda, you should submit that as an answer. – Civilian May 07 '15 at 02:08
  • OK, I posted it as an answer. – Kenton Varda May 07 '15 at 10:08

15 Answers15

61

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.

Kenton Varda
  • 41,353
  • 8
  • 121
  • 105
  • 13
    FYI, it should live at `$GOPATH/bin`. So do this: `export PATH=$PATH:$GOPATH/bin` – Masood Khaari Oct 07 '17 at 14:45
  • 6
    I have it in path and executable, but still report `Plugin failed with status code 1.` – Jiang YD Jan 05 '18 at 12:31
  • 3
    @JiangYD, I had the same problem. Looks like protoc couldn't expand paths like ~/go/bin. Make sure you are using the complete directory in your PATH settings like /home/johndoe/go/bin instead of ~/go/bin. – Renato Aquino Mar 05 '18 at 15:53
  • I have tried all the above suggestions. Still it fails to work for me. FYI, protoc-gen-go is not there for me under `$GOPATH/bin/` – darkdefender27 Mar 20 '18 at 09:29
  • 1
    @darkdefender27 do you have GOPATH set? If not the default is $HOME/go/ . protoc seems to be ok expanding $HOME instead of ~ so for me adding $HOME/go/bin to my path worked. – Shaun Bouckaert May 08 '18 at 12:27
  • 1
    I had the same issue but it was because GOPATH itself was not set within .bash_profile. So add the following line `export GOPATH=$(go env GOPATH)` above your `export PATH=$PATH:$GOPATH/bin` line inside the .bash_profile file. – Jimmy Shaw May 10 '18 at 00:01
31

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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Xibai Li
  • 311
  • 3
  • 3
31
  1. You should properly define your GO_PATH - where your go packages live. In other words, GO_PATH is your go workspace. The GO_PATH should be ~/go.

  2. protoc-gen-go should be in your PATH. While protoc-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
Quy Tang
  • 3,929
  • 1
  • 31
  • 45
13

On Ubuntu 18.04, this is verified working to solve this issue:

sudo apt-get install golang-goprotobuf-dev

james-see
  • 12,210
  • 6
  • 40
  • 47
00imvj00
  • 665
  • 7
  • 18
6

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.

Bhaskar Reddy
  • 81
  • 1
  • 6
4

How I solved:

  1. Add $GOPATH/bin to PATH by running export PATH=$PATH:$GOPATH/bin
  2. add export GOPATH=$(go env GOPATH) above export PATH=$PATH:$GOPATH/bin line inside the .bash_profile file.
  3. run go get -u for the required packages again.
  4. run the code protoc --go_out=../cloud/ *.proto in your case.
snowpeak
  • 797
  • 9
  • 25
3

I met the same problem.

$ protoc --go_out=plugins=grpc:pb/ *.proto
protoc-gen-go: program not found or is not executable
--go_out: protoc-gen-go: Plugin failed with status code 1.

The solution as below:

Find the installation directory of protoc-gen-go, it must be in your $PATH.

export PATH=$PATH:/path/to/dir

You'd better add it to your .bash_profile

echo $"export PATH=\$PATH:$(/path/to/dir)" >> ~/.bash_profile
source ~/.bash_profile

then everything is ok.

pangpang
  • 8,581
  • 11
  • 60
  • 96
3

What I did to solve this was:

copy protoc-gen-go from the go bin folder in go workspace to /usr/local/bin/

run your command as before in your case "protoc --go_out=../cloud/ *.proto"

  • I tried adding the PATH variables and restaring terminal or source to reload PATH variables. Copying the file fix all the stuff and generating code on ma Catalina is working now, thanks ! – Marco Feregrino Aug 17 '20 at 15:24
3

Directly from grpc documentation:

Go plugins for the protocol compiler:

Install the protocol compiler plugins for Go using the following commands:

$ export GO111MODULE=on  # Enable module mode
$ go get google.golang.org/protobuf/cmd/protoc-gen-go \
         google.golang.org/grpc/cmd/protoc-gen-go-grpc

Update your PATH so that the protoc compiler can find the plugins:

$ export PATH="$PATH:$(go env GOPATH)/bin"
Yrineu Rodrigues
  • 1,306
  • 14
  • 12
2

Mby will help for somebody. I'm on Fedora 29.

When I installed Go I did:

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

So I have my GOPATH set up. Next I do:

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

And my protoc compiler work lika a charm.

Dzintars
  • 1,410
  • 21
  • 29
1

On macOS, I had installed just protoc with brew install protobuf.

So, to get the go code generator, I also needed to do brew install protoc-gen-go.

Aditya M P
  • 5,127
  • 7
  • 41
  • 72
0

If you're using Fedora, ensure that the package "protoc-gen-go" is installed, and it's binary is in your shel PATH.

$sudo dnf install protoc-gen-go -y

0

If found this page because you get the error message in console when you run proto:

Protoc command not found

If you use linux then follow the instructions below:

  1. download the protoc file here https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.4 (i used to download the protoc-3.19.4-linux-x86_64.zip in my case.
  2. extract the files in this folder `/home/your_username/.local
  3. then you will have it like this: /home/your_username/.local/bin/protoc
  4. Profit. this will work by typing just "protoc" in your terminal
muinh
  • 535
  • 6
  • 14
0

enter image description here

I have installed protoc 3.20.0. But I didn't get the tag for generating the code for Golang. I have pasted the screenshot of all available tags.

  • 7 year old ticket. – R.J. Robinson Apr 15 '22 at 21:34
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 16 '22 at 01:08
-1

Ensure that your path to proton-gen-go in your PATH variable is absolute (i.e. /Users/me/go/bin instead of ~/go/bin.

Apparently protoc does not know how to expand ~.

Pep
  • 1,957
  • 2
  • 24
  • 40