打开https://golang.google.cn/dl/
解压下载好的包
tar -zxvf go1.13.3.linux-amd64.tar.gz
移动解压好的目录到/usr/local/下
mv go /usr/local/go
新建GOPATH目录
mkdir /opt/go
设置环境变量
vim /etc/profile
在末尾添加
export GOROOT=/usr/local/go
export GOBIN=$GOPATH/bin //一般设置GOPATH下的bin,意思为第三方包编译的可执行文件路径
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:/opt/go/bin
export GOPATH=/opt/go
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
保存并退出:wq
使其生效
source /etc/profile
验证安装是否成功
go version //查看当前安装版本
go env //显示环境变量信息
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/opt/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build396767069=/tmp/go-build -gno-record-gcc-switches"