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:
Many of the other responses address path issues but if it's not installed, you can install it using the following command:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
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 ~
.
They commented above 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
Make sure your GOBIN is set in the PATH
variable. Otherwise, you may encounter this problem. Check GOBIN
path by running go env
and confirm GOBIN
is not empty.
If it is empty then try like below
export GOPATH=$HOME/go
PATH=$PATH:$GOPATH/bin
protoc --go_out=plugins=grpc:. *.proto
Resolved by following the steps:
Install go library using: go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
vim ~/.bash_profile
export GO_PATH=~/go
export PATH=$PATH:/$GO_PATH/bin
source ~/.bash_profile
Reference: Unable to build protobuf to go endpoint
From the github repo this solution has worked for me.
Go version is go version go1.14.1 linux/amd64
Add this to .bashrc
and source it.
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN
https://github.com/golang/protobuf/issues/795