Use go get
to download the following packages:
go get google.golang.org/protobuf/cmd/protoc-gen-go
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
For setting GOPATH
and GOROOT
, follow the below procedure:
But, first, run go env
.
If you see that the Go is not installed, you can install it via Homebrew. If you see the output, then your Go is installed. It shows you all the environments that are set and are not.
If you see empty for GOPATH
:
Create any directory anywhere on your computer for Go projects in my case: ~/GO_PROJECTS then export GOPATH=~/GO_PROJECTS
.
If you see empty for GOROOT
:
Run which go
(on my computer: /usr/local/bin/go)
then edit your ~/.zshrc
file to add the following line export like this export GOROOT=/usr/local/go
.
You can also edit your ~/.zshrc
file to add the following line to set up the GOPATH
and GOROOT
:
If you have installed Go from the original pkg, download from https://golang.org/doc/install.
export GOPATH=$HOME/dev/go-workspace
export GOROOT=/usr/local/go
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
If you have installed Go using Homebrew.
export GOPATH=$HOME/dev/go-workspace
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
Save and exit your editor. Then, source your ~/.zshrc
.
source ~/.zshrc
brew install protoc-gen-go
or another plugin likebrew install protoc-gen-go-grpc
, thereafter probably got install in/usr/local/Cellar/protoc-gen-go/version/bin
, add it permanently either on .zshrc (recommend) or .bash_history or .bash_profile. check byprotoc-gen-go --version
simple! – Floorwalker