## 一、 Windows Golang搭建
### 直接进入[Golang下载官网](https://golang.google.cn/dl/)
![Golang下载官网.png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a70d0c29ae7a4fe18a07b16afab93d20~tplv-k3u1fbpfcp-watermark.image)
- #### 如果你是Win7 64位或者Win10,直接选择点击第一个go1.17.windows-amd64.msi,也可以根据个人需要选择下方各个版本的golang,我这里处于工作需要,下载的是go1.15.6 32位的,整个安装过程就不在过多叙述。
```golang
D:\CaoXun\WorkProject\Project\Myself>go version
go version go1.15.6 windows/386
```
## 二、Linux Golang搭建
### 可以进入官网下载[Golang下载官网](https://golang.google.cn/dl/)压缩文件go1.17.linux-amd64.tar.gz,也可以直接使用命令行进行下载
```golang
[root@k8s-master ~]# mkdir Tools && cd Tools
[root@k8s-master Tools]# wget https://dl.google.com/go/go1.17.linux-amd64.tar.gz
```
### 下载之后解压,把解压后的文件放入/usr/local,然后创建Golang环境需要的文件夹,并设置环境变量
```golang
[root@k8s-master Tools]# tar -xvf go1.17.linux-amd64.tar.gz
[root@k8s-master Tools]# ls
go go1.17.linux-amd64.tar.gz
[root@k8s-master Tools]# mv go /usr/local/
[root@k8s-master Tools]# cd
[root@k8s-master ~]# mkdir /Golang && cd /Golang
[root@k8s-master Golang]# mkdir bin pkg src
[root@k8s-master Golang]# vim /etc/profile
```
### 在/etc/profile文件最后添加如下
```golang
export GOROOT=/usr/local/go
export GOPATH=/Golang
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
```
### 使环境变量生效
```golang
[root@k8s-master Golang]# source /etc/profile
```
### 用如下命令查看是否安装完成并修改go拉取库的网址
```golang
[root@k8s-master Golang]# go version
go version go1.17 linux/amd64
[root@k8s-master Golang]# go env -w GOPROXY=https://goproxy.cn,direct
[root@k8s-master Golang]# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Golang/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/Golang/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/Golang"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3032662320=/tmp/go-build -gno-record-gcc-switches"
[root@k8s-master Golang]# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Golang/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/Golang/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/Golang"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1926810789=/tmp/go-build -gno-record-gcc-switches"
```
有疑问加站长微信联系(非本文作者))