Go 语言支持以下系统:
- Linux
- FreeBSD
- Mac OS X(也称为 Darwin)
- Window
先打开网址:https://golang.google.cn/dl/ 下载需要的版本,Win,Mac,Linux自行选择自己的环境 ,这里只介绍Linux环境的配置。
[root@kiccleaf ~]# wget https://golang.google.cn/dl/go1.15.linux-amd64.tar.gz
[root@kiccleaf ~]# tar zxvf go1.15.linux-amd64.tar.gz
[root@kiccleaf ~]# mv go /usr/local/
[root@kiccleaf ~]# vim /etc/profile
在文件底部增加:
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
保存退出后
[root@kiccleaf ~]# source /etc/profile
[root@kiccleaf ~]# go version
go version go1.15 linux/amd64
显示go环境安装成功,是不是有点太简单了?
来吧,第一个go程序
[root@kiccleaf ~]# vim helloword.go
helloword.go内容:
package main
import "fmt"
func main(){
fmt.Printf("Hello Word!\n");
}
[root@kiccleaf ~]# go build helloword.go
[root@kiccleaf ~]# ./helloword
Hello Word!
[root@kiccleaf ~]# du -sh helloword
2.0M helloword
编译好的文件还是有点大的,简单的一个Hello Word!需要2M的大小。