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/krYOlLmyspace#
此时,就安装了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$krYOlL
可见, 可以用sudo apt-get install golang-go
一件安装, 我们之前也说过apt-get
的强大。
既然我们已经安装了, 那先可以忽略sudo apt-get install golang-go
, 那要执行go run test.go, 怎么办呢? 很简单, 把这个路径加到PATH中就OK了, 如下:
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注册表,我真是烦透了。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对我们的支持。如果你想了解更多相关内容请krYOlL查看下面相关链接