linux下搭建go环境很简单:
1.下载go1.2.1.linux-386.tar.gz,网上到处有类似包,并放到linux目录下。
taogeqq@taogeqq-virtual-machine:~/myspace$ ls a.out go1.2.1.linux-386.tar.gz test.cpp test.go taogeqq@taogeqq-virtual-machine:~/myspace$
2.切换到root用户,在root下解压,解压即安装,多么绿色的软件啊:
root@taogeqq-virtual-machine:/home/taogeqq/myspace# tar zxvf go1.2.1.linux-386.tar.gz -C /usr/local/
可以看到, 在目录下多了go目录:
root@taogeqq-virtual-machine:/home/taogeqq/myspace# ls /usr/local bin etc games go include lib man sbin share src root@taogeqq-virtual-machine:/home/taogeqq/myspace#
此时,就安装了go环境,现在可以退出root用户了
3. 写一个test.go文件, 并测试:
taogeqq@taogeqq-virtual-machine:~/myspace$ ls a.out go1.2.1.linux-386.tar.gz test.cpp test.go taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ cat test.go package main import "fmt" func main(){ fmt.Println("hello world") fmt.Println("This is my first Go code") } taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ /usr/local/go/bin/go run test.go hello world This is my first Go code taogeqq@taogeqq-virtual-machine:~/myspace$
获取到了预期的结果。
有个问题, 我们执行go run test.go试下:
taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go 程序“go”尚未安装。 您可以使用以下命令安装: sudo apt-get install golang-go taogeqq@taogeqq-virtual-machine:~/myspace$
sudo apt-get install golang-goapt-get
sudo apt-get install golang-go
taogeqq@taogeqq-virtual-machine:~/myspace$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ vim /home/taogeqq/.bash_profile taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ cat /home/taogeqq/.bash_profile export PATH=$PATH:/usr/local/go/bin/ taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ source /home/taogeqq/.bash_profile taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/go/bin/ taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go hello world This is my first Go code taogeqq@taogeqq-virtual-machine:~/myspace$
其中/home/taogeqq是taogeqq的主目录。
linux下玩东西就是爽,NM的Windows注册表,我真是烦透了。
总结
版权声明:本站文章来源标注为YINGSOO的内容版权均为本站所有,欢迎引用、转载,请保持原文完整并注明来源及原文链接。禁止复制或仿造本网站,禁止在非www.yingsoo.com所属的服务器上建立镜像,否则将依法追究法律责任。本站部分内容来源于网友推荐、互联网收集整理而来,仅供学习参考,不代表本站立场,如有内容涉嫌侵权,请联系alex-e#qq.com处理。