Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
marcoippolito opened this issue Jan 30, 2019 · 29 comments
Closed

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

marcoippolito opened this issue Jan 30, 2019 · 29 comments

Comments

@marcoippolito
Copy link

Hi,
I correctly installed and protobuf in my Ubuntu 18.04.01 Server Edition following the steps here outlined:
https://github.com/protocolbuffers/protobuf/blob/master/src/README.md

and without any problems compiled the example found here:
https://developers.google.com/protocol-buffers/docs/cpptutorial

protoc --cpp_out=. ./addressbook.proto
-rw-rw-r-- 1 marco marco  49K Jan 30 11:26 addressbook.pb.cc
-rw-rw-r-- 1 marco marco  27K Jan 30 11:26 addressbook.pb.h
-rw-rw-r-- 1 marco marco  410 Jan 30 11:25 addressbook.proto

But when trying to do the same in golang:

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

Other information:

in my .bashrc I added the following lines:

export GOPATH=${HOME}/go:$PATH
export GOBIN=$HOME/go/bin:$PATH

go version:

go version go1.10.4 linux/amd64

How to make protoc-gen-go functioning?
Looking forward to your kind help.
Marco

@neild
Copy link
Contributor

neild commented Jan 30, 2019

See the Installation section of the package README here: https://github.com/golang/protobuf

Grab the code from the repository and install the proto package. The simplest way is to run go get -u github.com/golang/protobuf/protoc-gen-go. The compiler plugin, protoc-gen-go, will be installed in $GOPATH/bin unless $GOBIN is set. It must be in your $PATH for the protocol compiler, protoc, to find it.

@neild neild closed this as completed Jan 30, 2019
@fclinux
Copy link

fclinux commented Nov 17, 2019

Hello Neild,
I spend ~ 8 hours for check and follow your guid but I would tell you that this still stuck with this newest version. please dont try to close this and believe you are the right

@nikhs247
Copy link

nikhs247 commented Nov 20, 2019

Hello Neild,
I spend ~ 8 hours for check and follow your guid but I would tell you that this still stuck with this newest version. please dont try to close this and believe you are the right

Hi fclinux,
I had the same issue. Can you please check if you added GOPATH and GOBIN to your PATH?
On adding the GOPATH and GOBIN to path, my issue was resolved.

Thanks
Nikhil

@chezixin
Copy link

chezixin commented Dec 6, 2019

您好Neild,
我花了大约8个小时进行检查,并按照您的指南进行操作,但是我会告诉您,这个最新版本仍然存在。请不要试图关闭这个并相信你是正确的

嗨,fclinux,
我有同样的问题。您能否检查是否已将GOPATH和GOBIN添加到PATH中?
在将GOPATH和GOBIN添加到路径时,我的问题已解决。

谢谢
Nikhil

no,I'm pretty sure I've added the path, but I still get the same error message

  1 export GOPATH=/Users/chezixin/go
  2 export GOBIN=/Users/chezixin/go/bin
  3 
  4 export GO111MODULE=on
  5 # export GOPROXY=https://goproxy.io
  6 export GOPROXY=https://goproxy.cn
  7 
  8 
  9 export PATH="$PATH:/Applications/Postgres.app/Contents/Versions/12/bin:/Users/chezixin/flutterSDK/flutter/bin:/usr/local/go/bin:$GOPATH:$GOBIN'"
 10 
czxmac:~ chezixin$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Applications/Postgres.app/Contents/Versions/latest/bin:/Applications/Postgres.app/Contents/Versions/12/bin:/Users/chezixin/flutterSDK/flutter/bin:/usr/local/go/bin:/User/chezixin:/Users/chezixin/go/bin':/Applications/Postgres.app/Contents/Versions/12/bin:/Users/chezixin/flutterSDK/flutter/bin:/usr/local/go/bin:/Users/chezixin/go:/Users/chezixin/go/bin'

@fclinux
Copy link

fclinux commented Dec 6, 2019 via email

@iwita
Copy link

iwita commented Dec 11, 2019

Hello guys,
My problem was fixed after adding both GOPATH and GOROOT in PATH as @neild said.
use :
export PATH=$PATH:$HOME/go/bin, in order to add the GOPATH and
export PATH=$PATH:/usr/local/go/bin, in order to add GOROOT

@rickynyairo
Copy link

I had this problem as well recently [using ubuntu 18.04]
I found a long-lasting solution by adding the following lines to .bashrc:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN

@natewilson
Copy link

Another quick fix: Be sure the absolute path shows up in your $PATH Something beginning with ~/ can cause the plugin not to be found.

@dzintars
Copy link

Tnx @rickynyairo . Short and precise without trying to be too smart. :)

@JulianToledano
Copy link

I had this problem as well recently [using ubuntu 18.04]
I found a long-lasting solution by adding the following lines to .bashrc:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN

That worked for me 😄 👍
The reason as explained here is that protoc-gen-go must be in your system PATH not just in go env.

@nextonr
Copy link

nextonr commented Oct 22, 2020

Another quick fix: Be sure the absolute path shows up in your $PATH Something beginning with ~/ can cause the plugin not to be found.

you are pretty right.

@avdept
Copy link

avdept commented Dec 28, 2020

Can we specify path to protoc-gen-go manually? I dont want to push protoc-gen-go to my PATH because I have few different versions of protoc-gen-go and I need each of them to work separately

@neild
Copy link
Contributor

neild commented Dec 29, 2020

Can we specify path to protoc-gen-go manually?

Yes, see the --plugin flag for protoc.

@avdept
Copy link

avdept commented Feb 2, 2021

For any future lurkers here you can do it like
--plugin=protoc-gen-go-grpc=PATH_TO_BINARY

@MaDOS
Copy link

MaDOS commented Feb 9, 2021

In my case go get installed everything correctly and my path was set correctly after some time I noticed that the binary installed by go get just was named incorrectly!
I had to rename protoc-gen-go-grpc to protoc-gen-go_grpc and suddenly everything worked.
I verified this by deleting and again installing the plugin by go get. (On my Windows 10 machine and also on its WSL2 Ubuntu) both had a protoc-gen-go-grpc after the install which does not match the protoc-gen-go_grpc the protoc compiler exspects.

@puellanivis
Copy link
Collaborator

I had to rename protoc-gen-go-grpc to protoc-gen-go_grpc and suddenly everything worked.

You are likely accidentally using --plugin=protoc-gen-go_grpc The file name protoc-gen-go-grpc is the correct binary name.

@avdept
Copy link

avdept commented Feb 9, 2021

I've created a simple GUI for protoc CLI, feel free to check it out. Just needs binaries to be fed in and your proto files.
https://github.com/avdept/Protobuf-GUI-Compiler

@dumbjarvis
Copy link

I had to rename protoc-gen-go-grpc to protoc-gen-go_grpc and suddenly everything worked.

You are likely accidentally using --plugin=protoc-gen-go_grpc The file name protoc-gen-go-grpc is the correct binary name.

can you plz copy the full cmd, i think the docs are outdated

@willDrr
Copy link

willDrr commented Sep 15, 2021

I had this problem as well recently [using ubuntu 18.04]
I found a long-lasting solution by adding the following lines to .bashrc:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN

That worked for me. I'm using Ubuntu 20.04. Go version go version go1.17

@adeniyistephen
Copy link

@willDrr Can you explain how you go about it?
I downloaded the .taz.gz source file from github I extracted it and copied the build to my $GOPATH/bin and letter edited my .bashrc with the above commands, but mine still did not work.

@willDrr
Copy link

willDrr commented Oct 9, 2021

@adeniyistephen I don't know man. I just pasted the 4 four lines above and it worked. I can't remember how did I install Go.

These are the lines in my .bashrc related to Go

export PATH=$PATH:/usr/local/go/bin
export PATH="$PATH:/usr/local/protobuf/bin"

//taked from #795 (comment)
//and it worked...
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN

@adeniyistephen
Copy link

adeniyistephen commented Oct 9, 2021

@willDrr what is inside your $PATH:/usr/local/protobuf/bin"?
ND did you set the path by yourself in the .bashrc file or that was how it was when you downloaded it?
If you don't mind, what was the command you used to compile the .proto file.
I also don't have any protobuf dir in my usr/local, that's why I'm asking how you downloaded yours?

@willDrr
Copy link

willDrr commented Oct 9, 2021

@adeniyistephen I echoed and this is what I have
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/loc al/games:/snap/bin:/usr/local/go/bin:/usr/local/protobuf/bin:/usr/local/go:/root /go:/root/go/bin:/usr/local/protobuf/bin/

@adeniyistephen
Copy link

Ok cool, I just sent you a mail.

@ducpt1012
Copy link

I had this problem as well recently [using ubuntu 18.04] I found a long-lasting solution by adding the following lines to .bashrc:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN

Thanks, it works in the Mac OS environment. Save my life!

@justinfarrelldev
Copy link

Hello Neild,
I spend ~ 8 hours for check and follow your guid but I would tell you that this still stuck with this newest version. please dont try to close this and believe you are the right

Hi fclinux, I had the same issue. Can you please check if you added GOPATH and GOBIN to your PATH? On adding the GOPATH and GOBIN to path, my issue was resolved.

Thanks Nikhil

This fixed the issue I was having! I'm using Fish and some of the commands were different for me. If anyone runs into this in the future, nano ~/.config/fish/config.fish and then make sure that your variables are set correctly.

@toannd96
Copy link

toannd96 commented Jul 14, 2022

Thanks, it works in the Ubuntu 20.04 environment. Save my life!

@RicHincapie
Copy link

See the Installation section of the package README here: https://github.com/golang/protobuf

Grab the code from the repository and install the proto package. The simplest way is to run go get -u github.com/golang/protobuf/protoc-gen-go. The compiler plugin, protoc-gen-go, will be installed in $GOPATH/bin unless $GOBIN is set. It must be in your $PATH for the protocol compiler, protoc, to find it.

For me to work a protoc command with a make file inside alpine container, I had to install this:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/golang/protobuf/protoc-gen-go@latest

@CaioLuColaco
Copy link

I had this problem as well recently [using ubuntu 18.04] I found a long-lasting solution by adding the following lines to .bashrc:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN

That worked for me. I'm using Ubuntu 22.04.2. Go version go version go1.20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests