centos7安装golang

1.下载

wget https://gomirrors.org/dl/go/go1.14.2.linux-amd64.tar.gz

可以手动下载然后上传,也可以直接执行上面的命令

附:下载地址:

Go官网下载地址:https://studygolang.com/dl

Go官方镜像站(推荐): https://golang.google.cn/dl/

2.解压

sudo tar -C /usr/local -zxf go1.14.2.linux-amd64.tar.gz

3.建立工作目录

mkdir -p /home/xxgis/go/src /home/xxgis/go/pkg /home/xxgis/go/bin

4.配置环境变量

sudo vi /etc/profile

增加以下三行

export GOROOT=/usr/local/go

export GOPATH=/home/xxgis/go

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

保存退出。

执行生效

source /etc/profile

5.检查安装是否成功

[ test]$ go version

go version go1.14.2 linux/amd64

[ go]$ go env

GO111MODULE=""

GOARCH="amd64"

GOBIN=""

GOCACHE="/home/xxgis/.cache/go-build"

GOENV="/home/xxgis/.config/go/env"

GOEXE=""

GOFLAGS=""

GOHOSTARCH="amd64"

GOHOSTOS="linux"

GOINSECURE=""

GONOPROXY=""

GONOSUMDB=""

GOOS="linux"

GOPATH="/home/xxgis/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"

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-build352528101=/tmp/go-build -gno-record-gcc-switches"

安装完成。

6.测试一下

[ src]$ mkdir test

[ src]$ cd test

[ test]$ pwd

/home/xxgis/go/src/test

[ test]$ vi main.go

package main

import "fmt"

func main() {

    fmt.Println("Hello, World!")

}

~

"main.go" [New] 8L, 80C written

[ test]$

[ test]$ go run main.go

Hello, World!

测试成功!

相关推荐