安装包下载
go1.14.1.linux-amd64.tar.gz
解压到指定目录下
1
| $ tar -C /usr/local -xzf go1.14.1.linux-amd64.tar.gz
|
环境变量配置
环境变量设置可以选择 /etc/profile
或 ~/.bashrc
Go环境变量配置如下
1 2 3 4 5
| export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin export GOPATH=~/go export GO111MODULE=on
|
刷新环境变量
测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| $ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/xxxx/.cache/go-build" GOENV="/home/xxxx/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/xxxx/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build248485667=/tmp/go-build -gno-record-gcc-switches"
|
Go 工作空间
1 2 3 4 5
| $ tree . ├── bin ├── pkg └── src
|
Hello World
代码
1 2 3 4 5 6 7
| package main
import "fmt" func main(){ fmt.Printf("hello world\n") }
|
执行
1 2
| $ go run hello.go hello world
|
至此,Go
开发环境搭建完成