golang--安装golang并安装grpc-grpcgateway环境

安装goland环境

下载golang安装包,国内环境打开https://studygolang.com/dl,国外环境打开https://golang.google.cn/dl/下载对应系统的安装包,这里以linux环境为例。

wget https://dl.google.com/go/go1.12.8.linux-amd64.tar.gz

执行安装

// 解压
tar xvf go1.12.8.linux-amd64.tar.gz

// 移动目录到系统目录
mv go /usr/local

配置环境变量,写入GOROOT、GOPATH等必要信息

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的环境是否配置正确。

安装Protocol Buffers v3

先到github下载稳定版安装包wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protobuf-all-3.9.1.tar.gz

// 解压
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

安装grpc

安装grpc有两种方法,最简单的是使用go get -u google.golang.org/grpc,但是此方法需要合理上网。

第二种方法使用github安装

cd $GOPATH/src
mkdir google.golang.org
cd google.golang.org/
git clone https://github.com/grpc/grpc-go grpc

安装Protoc Plugin

安装Protoc Plugin使用go get -u github.com/golang/protobuf/protoc-gen-go

安装grpc-gateway

下载grpc-gateway主文件

安装grpc-gateway同样有两种方法,go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway,直接使用go get 安装,此方法有一些依赖需要从google下载,所以需要合理上网。国内推荐使用第二种方法:

cd $GOPATH/src/github.com
mkdir grpc-ecosystem
cd grpc-ecosystem
git clone https://github.com/grpc-ecosystem/grpc-gateway.git

编译安装yaml

yaml是编译安装protoc-gen-grpc-gateway的必备文件

cd $GOPATH/src/github.com
mkdir ghodss
cd ghodss
git clone https://github.com/ghodss/yaml.git

编译安装glog

cd $GOPATH/src/github.com/golang
git clone https://github.com/golang/glog.git

安装yaml.v2

go get gopkg.in/yaml.v2

编译安装protoc-gen-grpc-gateway

cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go build
mv protoc-gen-grpc-gateway $GOPATH/bin

编译安装protoc-gen-swagger

cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go build
mv protoc-gen-swagger $GOPATH/bin
posted @ 2019-08-15 13:57  Leur  阅读(1693)  评论(1编辑  收藏  举报