Foreword:
The go language is basically the same as Java, Python, C language, etc., and it also needs to integrate the language environment in the system. The languages are basically the same, and various system architectures are supported, such as mac, Windows, and linux systems. This article only takes the most commonly used Windows and centos as examples to explain the construction of the go language environment.
Downloads - The Go Programming Language
Choose the appropriate version to download according to your server version
Note, this cannot be downloaded:
[root@EULER2 ~]# cat /etc/redhat-release
EulerOS release 2.0 (SP5)
[root@EULER2 ~]# uname -m
x86_64
Therefore, download the following version:
[root@EULER2 ~]# ls go1.19.6.linux-amd64.tar.gz
go1.19.6.linux-amd64.tar.gz
1. Unzip the deployment and configure environment variables
tar xf go1.19.6.linux-amd64.tar.gz
mv go /usr/local/
vim /etc/profile
##末尾添加如下内容:
export GOROOT=/usr/local/go
export GOPATH=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
###激活变量
source /etc/profile
two,
test
Correctly output the version of go
[root@EULER2 ~]# go version
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
go version go1.19.6 linux/amd64
[root@EULER2 ~]# go env
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
GO111MODULE=""
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.6"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3630755021=/tmp/go-build -gno-record-gcc-switches"
The environment deployment of go language is still very simple.