这篇文章上次修改于 2772 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

Linux(centos redhat ) 安装

1.访问官方地址:
https://golang.org/dl/
由于相关ZC你懂的,最好能翻墙下

2.下载64位绿色包:
https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz

3.下载完毕后:
假定你想要安装Go的目录为$GO_INSTALL_DIR,后面替换为相应的目录路径。
解压缩tar.gz包到安装目录下:

tar -xvf go1.8.3.linux-amd64.tar.gz -C $GO_INSTALL_DIR

4.添加环境变量vim /etc/profile,加入如下几行

export PATH=$PATH:$GO_INSTALL_DIR/go/bin

export GOROOT= $GO_INSTALL_DIR/go

export GOBIN=$GOROOT/bin

export GOPATH= $GO_INSTALL_DIR/go/data  注意 $GO_INSTALL_DIR 为你的go的安装或者解压目录

5.生效环境变量

source /etc/profile

然后执行go

[root@centos ~] go
Go is a tool for managing Go source code.

Usage:

    go command [arguments]

The commands are:

    build       compile packages and dependencies
    clean       remove object files
    doc         show documentation for package or symbol
    env         print Go environment information
    bug         start a bug report
    fix         run go tool fix on packages
    fmt         run gofmt on package sources
    generate    generate Go files by processing source
    get         download and install packages and dependencies
    install     compile and install packages and dependencies
    list        list packages
    run         compile and run Go program
    test        test packages
    tool        run specified go tool
    version     print Go version
    vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

    c           calling between Go and C
    buildmode   description of build modes
    filetype    file types
    gopath      GOPATH environment variable
    environment environment variables
    importpath  import path syntax
    packages    description of package lists
    testflag    description of testing flags
    testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.

看到以上信息,说明go环境已经搭建起来

查看go的版本

[root@centos ~] go version
go version go1.8 linux/amd64