一、 通过yum 安装go
yum install go
二、 查看go语言环境
[root@iZhp3349o7pntezql2q5puZ ~]# go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build127476861=/tmp/go-build -gno-record-gcc-switches"
注意记录 GOROOT 和 GOPATH
三、 配置go语言环境
讲GOROO、GOPATH 、代理和bin路径配置到环境变量中
export GOROOT="/usr/lib/golang"
export GOPATH="/root/go"
export GOPROXY=https://goproxy.cn
export GO111MODULE=on
export PATH=$GOROOT/bin:$GOPATH/bin:${PATH}
使配置生效
source /etc/profile
四、 校验环境变量
GOROOT 和GOPATH 可正确打印,表示配置成功
[root@iZhp3349o7pntezql2q5puZ ~]# echo $GOPATH
/root/go
[root@iZhp3349o7pntezql2q5puZ ~]# echo $GOROOT
/usr/lib/golang
网友评论