到官方https://golang.org/dl/
或者 https://www.golangtc.com/download 下载安装包
wget https://www.golangtc.com/static/go/1.9/go1.9.linux-amd64.tar.gz
tar zxvf go1.9.linux-amd64.tar.gz -C /usr/local
新建GOPATH目录
mkdir -p /www/golang
vim /etc/profile
export GOROOT=/usr/local/go
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
export GOPATH=/www/golang
:wq保存 使其生效
source /etc/profile
查看是否配置成功
go version
go version go1.9 linux/amd64
简单测试:
cd /www/golang
vim hello.go
package main
import "fmt"
func main() {
fmt.Println("Hello, world")
}
:wq
go run hello.go
Hello, world