1.从官网下载go的pkg安装包进行安装
2.打开终端输入vi ~/.bash_profile,系统如果没有的话会自动新建该文件(本人的没有…)
3. 写入以下内容
export GOROOT=/usr/local/go
export PATH=
$PATH:
$GOROOT/bin
export GOPATH=
$HOME/yourpath
4.终端输入source ~/.bash_profile
5.最后是测试,本人安装版本是go1.6
终端输入:go,输出以下内容
Go is a tool
for managing Go
source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
doc show documentation
for package or symbol
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
generate generate Go files by processing
source
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use
"go help [command]" for more information about a command.
Additional
help topics:
c calling between Go and C
buildmode description of build modes
filetype file types
gopath GOPATH environment variable
environment environment variables
importpath import path syntax
packages description of package lists
testflag description of testing flags
testfunc description of testing functions
Use
"go help [topic]" for more information about that topic.
终端上输入go env,输出以下内容:
GOARCH=
"amd64"
GOBIN=
""
GOEXE=
""
GOHOSTARCH=
"amd64"
GOHOSTOS=
"darwin"
GOOS=
"darwin"
GOPATH=
""
GORACE=
""
GOROOT=
"/usr/local/go"
GOTOOLDIR=
"/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT=
"1"
CC=
"clang"
GOGCCFLAGS=
"-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX=
"clang++"
CGO_ENABLED=
"1"
6.GOPATH解释:GOPATH变量,Go从1.1版本开始必须设置这个变量,而且不能和Go的安装目录一样,这个目录用来存放Go源码,Go的可运行文件,以及相应的编译之后的包文件。
7.最后推荐一些学习go的书籍和项目
go源码Go Web 编程awesome-goGo入门指南Asta谢beegostathub-go
有问题或建议请联系邮箱:981017952@qq.com,qq:981017952
转载请注明原文地址: https://ju.6miu.com/read-1201248.html