Centos7安装GO

1.下载

wget https://studygolang.com/dl/golang/go1.13.6.linux-amd64.tar.gz

2.解压

[root@localhost local]# tar -C /usr/local -xzf go1.13.6.linux-amd64.tar.gz 
[root@localhost go]# cd /usr/local
[root@localhost go]# cd /usr/local
[root@localhost local]# ll
drwxr-xr-x  10 root root 272 Jan 10 03:05 go

3.修改环境变量

[root@localhost local]# vi /etc/profile
末尾增加
export PATH=$PATH:/usr/local/go/bin
[root@localhost local]# source /etc/profile

4.编写helloworld测试

[root@localhost hello]# vi helloworld.go

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

[root@localhost hello]# go build helloworld.go   //编译
[root@localhost hello]# ll
total 1984
-rwxr-xr-x 1 root root 2025490 Jan 13 11:50 helloworld
-rw-r--r-- 1 root root      82 Jan 13 11:49 helloworld.go
[root@localhost hello]# chmod +x helloworld
[root@localhost hello]# ./helloworld   //执行
hello, world

因为go是编译性语言。一次编译多处可以执行。所以把helloword拷贝到任何目录都能正常执行,并且可以脱离go环境执行。只不过要求操作系统一致。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容