首页 > 系统 > Linux > 正文

linux下搭建go环境的安装配置讲解

2024-08-28 00:04:01
字体:
来源:转载
供稿:网友

linux下搭建go环境很简单:

1.下载go1.2.1.linux-386.tar.gz,网上到处有类似包,并放到linux目录下。

taogeqq@taogeqq-virtual-machine:~/myspace$ lsa.out go1.2.1.linux-386.tar.gz test.cpp test.gotaogeqq@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/localbin etc games go include lib man sbin share srcroot@taogeqq-virtual-machine:/home/taogeqq/myspace# 

此时,就安装了go环境,现在可以退出root用户了

3.  写一个test.go文件, 并测试:

taogeqq@taogeqq-virtual-machine:~/myspace$ lsa.out go1.2.1.linux-386.tar.gz test.cpp test.gotaogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ cat test.gopackage mainimport "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.gohello worldThis is my first Go codetaogeqq@taogeqq-virtual-machine:~/myspace$ 

获取到了预期的结果。

有个问题, 我们执行go run test.go试下:

taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go程序“go”尚未安装。 您可以使用以下命令安装:sudo apt-get install golang-gotaogeqq@taogeqq-virtual-machine:~/myspace$ 

可见, 可以用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/gamestaogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ vim /home/taogeqq/.bash_profiletaogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ cat /home/taogeqq/.bash_profileexport PATH=$PATH:/usr/local/go/bin/taogeqq@taogeqq-virtual-machine:~/myspace$ taogeqq@taogeqq-virtual-machine:~/myspace$ source /home/taogeqq/.bash_profiletaogeqq@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.gohello worldThis is my first Go codetaogeqq@taogeqq-virtual-machine:~/myspace$ 

其中/home/taogeqq是taogeqq的主目录。

linux下玩东西就是爽,NM的Windows注册表,我真是烦透了。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表