下载golang安装包,国内环境打开https://studygolang.com/dl
,国外环境打开https://golang.google.cn/dl/
下载对应系统的安装包,这里以linux环境为例。
html
wget https://dl.google.com/go/go1.12.8.linux-amd64.tar.gz
执行安装linux
// 解压 tar xvf go1.12.8.linux-amd64.tar.gz // 移动目录到系统目录 mv go /usr/local
配置环境变量,写入GOROOT、GOPATH等必要信息c++
vi /etc/profile // 写入GOPATH、GOROOT信息 export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin export GOPATH=$HOME/go/ export PATH=$PATH:$GOPATH/bin/ // 添加完成后刷新环境变量 source /etc/profile
输入goenv查看当前golang的环境是否配置正确。git
先到github下载稳定版安装包wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protobuf-all-3.9.1.tar.gz
github
// 解压 tar xvf protobuf-all-3.9.1.tar.gz // 安装gcc c++ 参考:https://www.cnblogs.com/walkman-sky/p/9426775.html // 执行安装 ./configure make && make install
检查是否安装成功protoc --version
golang
安装grpc有两种方法,最简单的是使用go get -u google.golang.org/grpc
,可是此方法须要合理上网。ui
第二种方法使用github安装google
cd $GOPATH/src mkdir google.golang.org cd google.golang.org/ git clone https://github.com/grpc/grpc-go grpc
安装Protoc Plugin使用go get -u github.com/golang/protobuf/protoc-gen-go
code
安装grpc-gateway一样有两种方法,go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
,直接使用go get 安装,此方法有一些依赖须要从google下载,因此须要合理上网。国内推荐使用第二种方法:htm
cd $GOPATH/src/github.com mkdir grpc-ecosystem cd grpc-ecosystem git clone https://github.com/grpc-ecosystem/grpc-gateway.git
yaml是编译安装protoc-gen-grpc-gateway的必备文件
cd $GOPATH/src/github.com mkdir ghodss cd ghodss git clone https://github.com/ghodss/yaml.git
cd $GOPATH/src/github.com/golang git clone https://github.com/golang/glog.git
go get gopkg.in/yaml.v2
cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway go build mv protoc-gen-grpc-gateway $GOPATH/bin
cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger go build mv protoc-gen-swagger $GOPATH/bin