现在的位置: 首页 > 综合 > 正文

ubuntu下golang 环境安装步骤

2017年12月26日 ⁄ 综合 ⁄ 共 794字 ⁄ 字号 评论关闭

1,环境变量设置

~$ cd 

~$ mkdir go

~$ mkdir bin

~$ sudo  gedit .bashrc

在bash文件的最后添加如下代码来设置目录变量:

 

export GOROOT=$HOME/go
export GOOS=linux
export GOARCH=386
export GOBIN=$HOME/bin
保存文件
~$ source .bashrc
~$ sudo gedit /etc/profile
在文件最后修改PATH,PATH尚未存在,直接添加如下语句,否则添加

export PATH=$HOME/bin:$PATH
保存文件
~$ source /etc/profile
执行env | grep '^GO'测试是否已经正确设置GO的环境变量

2,获取资源

 

~$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT

如果不成功,则先安装mercurial:

~$ sudo apt-get install mercurial

3,安装

~$ sudo apt-get install bison gcc libc6-dev ed

~$ cd $GOROOT/src

~$ ./all.bash

 

等待几分钟,最后它会自测出现--- cd ../test

~$ cd

~$ mkdir helloGo
~$ cd helloGo
~$ cat >hello.go <<EOF
 > package main
 > import "fmt"
 > func main() {
 > fmt.Printf("hello, world/n"
 >  }
 >  EOF
~$ 8g hello.go
~$ 8l hello.8
~$ ./8.out
hello, world

 

4,参考

1,golang官网 http://golang.org/

原文地址:http://blog.csdn.net/xinshg/article/details/5199651

抱歉!评论已关闭.