Home >Backend Development >Golang >Why Does 'protoc' Fail with 'protoc-gen-go: Program Not Found' and How Do I Fix It?
Unable to Generate Code with "Protoc" Due to "protoc-gen-go: Program Not Found" Error
Question:
I am facing the following error when generating code with "protoc":
"protoc-gen-go: program not found or is not executable --go_out: protoc-gen-go: Plugin failed with status code 1."
Despite installing the necessary libraries, such as google.golang.org/grpc and github.com/golang/protobuf/protoc-gen-go, I cannot resolve this issue.
Resolution:
For Go versions 1.17 and above, the installation of executables using go get is deprecated. Instead, use go install:
1. Update Environment Variables:
Edit ~/.bashrc or ~/.zshrc and add the following lines:
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
2. Install Protobuf and gRPC Plugins:
Install the Protobuf and gRPC plugins using the following commands:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
3. Generate Code:
You should now be able to generate code using protoc as follows:
protoc --go-grpc_out=. *.proto
The above is the detailed content of Why Does 'protoc' Fail with 'protoc-gen-go: Program Not Found' and How Do I Fix It?. For more information, please follow other related articles on the PHP Chinese website!