机器centos7.3:
1安装
运行 yum install golang安装go(默认安装路径:/usr/lib/golang)
没有yum的下载,并安装。网址https://golang.google.cn/dl/.(参考:https://www.cnblogs.com/jxxiaocao/p/12175954.html)
2添加环境变量
vim .bashrc_profile
#Golang
export GOROOT=/usr/lib/golang
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
#GOPATH
export GOPATH=/home/panda/Golang
export PATH=$PATH:$GOPATH/bin
go modules$GOPATH/pkg/
soure.bashrc_profile
3 hello world
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World")
}
执行:$go build hello.go编译
然后 $ ./hello
也可以go run hello.go