前言:
go语言和Java,Python,C语言等等基本一样,也是需要在系统内集成语言环境的。语言基本都一样,支持各种系统架构,比如,mac,Windows,linux系统支持。本文仅以最为常用的Windows和centos为例讲解go语言环境的搭建。
Downloads - The Go Programming Language
根据自己服务器的版本选择合适的版本下载
注意,这个不能下载:
[root@EULER2 ~]# cat /etc/redhat-release
EulerOS release 2.0 (SP5)
[root@EULER2 ~]# uname -m
x86_64
因此,下载如下版本:
[root@EULER2 ~]# ls go1.19.6.linux-amd64.tar.gz
go1.19.6.linux-amd64.tar.gz
一,解压部署并配置环境变量
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
二,
测试
正确输出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"
go语言的环境部署还是非常简单的。