国内资源Go语言中文网https://studygolang.com/dl
一、下载安装包
wget https://studygolang.com/dl/golang/go1.11.linux-amd64.tar.gz
二、解压安装
注:go安装包是已经编译,直接将解压后的包放置在/usr/local/下
tar zxvf go1.11.linux-amd64.tar.gz -C /usr/local
三、配置go环境变量
vim /etc/profile
export GOROOT=/usr/local/go
export GOPATH=/home/go_code
export GOBIN=/usr/local/go/bin
export PATH=$PATH:$GOROOT
source /etc/profile
四、检测go版本
go version
go version go1.11 linux/amd64
五、检测go环境
go env
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/go_code"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build843021042=/tmp/go-build -gno-record-gcc-switches"
六、配置go项目目录结构
go code目录:/home/go_code
源码存放路径:/home/go_code/src
二进制文件存放路径:/home/go_code/bin
依赖包存放路径:/home/go_code/pkg
七、测试程序
cat test.go
package main
import (
"fmt"
)
func main() {
fmt.Printf("hello world")
}
go run test.go
hello world
有疑问加站长微信联系(非本文作者)