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

前端 未结 6 1452
逝去的感伤
逝去的感伤 2021-01-02 03:34

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:

相关标签:
6条回答
  • 2021-01-02 04:08

    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
    
    0 讨论(0)
  • 2021-01-02 04:10

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

    0 讨论(0)
  • 2021-01-02 04:10

    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
    
    0 讨论(0)
  • 2021-01-02 04:10

    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
    
    0 讨论(0)
  • 2021-01-02 04:24

    Resolved by following the steps:

    Install go library using: go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

    1. Run vim ~/.bash_profile
    2. Add:
    export GO_PATH=~/go
    export PATH=$PATH:/$GO_PATH/bin
    
    1. Run source ~/.bash_profile

    Reference: Unable to build protobuf to go endpoint

    0 讨论(0)
  • 2021-01-02 04:28

    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

    0 讨论(0)
提交回复
热议问题