Ubuntu16.04下搭建Go语言环境

Posted kluan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu16.04下搭建Go语言环境相关的知识,希望对你有一定的参考价值。

1. 安装GO

sudo apt-get install golang-go

2. 设置Go环境变量

打开终端,输入命令:

export GOROOT=$HOME/go
export PATH=$GOROOT/bin:$PATHU

3. 设置go代码目录

sudo mkdir Applications/go

4.  测试安装

完成安装后,新建一个文档来测试环境是否搭建成功:

Example helloWorld.go

package main
 
    import (
        "fmt"
         "runtime"
    )

    func main() {
        fmt.Println("Hellow World!", runtime.Version())
    }    

执行go run helloWorld.go, 应该会打印出:

或者go build helloWorld.go,将生成helloWorld.sh,./helloWorld也可以运行。

Hellow World! %!(EXTRA string=go1.6.2)

以上是关于Ubuntu16.04下搭建Go语言环境的主要内容,如果未能解决你的问题,请参考以下文章