您的位置:首页 > 运维架构 > Linux

centos安装GO

2015-11-04 13:55 453 查看
1,下载 go1.5.1.linux-amd64.tar.gz

2,将go解压到/opt,个人喜好罢了
[root@localhost ~]# tar -C /opt -xzf ./go1.5.1.linux-amd64.tar.gz

3,添加环境变量

GOPATH是工作目录,
GOROOT表示指出go的根目录位置 ps:在自定义程序的安装位置后,需要设置这个
export GOROOT=/opt/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/goTest
export GOBIN=$GOPATH/bin

[root@localhost ~]# vim /etc/profile

[root@localhost ~]# source /etc/profile

[root@localhost ~]# mkdir ./goTest/src/test

[root@localhost test]# touch ./hello.go

写入内容到hello.go:
package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

[root@localhost src]# cd ..

[root@localhost src]# go install test/hello.go
[root@localhost src]# $GOBIN/hello
hello, world

到这里,你的go就算安装好了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: