Читать книгу Practical Go - Amit Saha - Страница 14

Linux and macOS

Оглавление

To install the compiler, run the following steps for Linux or macOS:

1 Download the latest release (3.16.0 at the time of this book's writing) file from https://github.com/protocolbuffers/protobuf/releases, corresponding to your operating system and architecture. Look for the files in the Assets section. For example, for Linux on a x86_64 system, download the file named protoc-3.16.0-linux-x86_64.zip. For macOS, download the file named protoc-3.16.3-osx-x86_64.zip .

2 Next, extract the file contents and copy them to your $HOME/.local directory using the unzip command: $ unzip protoc-3.16.3-linux-x86_64.zip -d $HOME/.local.

3 Finally, add the $HOME/.local/bin directory to your $PATH environment variable: $ export PATH="$PATH:$HOME/.local/bin" in your shell's initialization script, such as $HOME/.bashrc for Bash shell and .zshrc for Z shell.

Once you have completed the preceding steps, open a new terminal window, and run the command protoc --version :

$ protoc --version libprotoc 3.16.0

If you see output like the one above, you are ready to move on to the next step.

To install the protobuf plug-in for Go, protoc-gen-go (release v1.26), run the following command from a terminal window:

$ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26

To install the gRPC plug-in for Go, protoc-gen-go-grpc (release v1.1) tool, run the following command:

$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1

Then add the following to your shell's initialization file ($HOME/.bashrc or $HOME/.zshrc) :

$ export PATH="$PATH:$(go env GOPATH)/bin"

Open a new terminal window, and run the following commands:

$ protoc-gen-go --version protoc-gen-go v1.26.0 $ protoc-gen-go-grpc --version protoc-gen-go-grpc 1.1.0

If you see an output like above, the tools have been installed successfully.

Practical Go

Подняться наверх