一·、Go語言的官方網站
https://golang.org/dl/
2、安裝Go語言
Linux版本:mac版本和windows版本安裝沒啥說的,一直「ok」「下一步」就能夠了css
tar zxf go1.11.4.linux-amd64.tar.gz mv go /usr/local/ mkdir -p /usr/local/go/gocode/{bin,pkg,src}
解釋:gocode:是工做空間,涉及源代碼的存放和包的管理,生產環境下建議放在用戶我的目錄下。html
文件夾 | 做用 |
---|---|
bin | 存放編譯後的可執行程序 |
pkg | 存放編譯後的包文件(.a文件) |
src | 存放源代碼 |
3、設置GOPATH和GOROOT環境變量linux
vim /etc/profileandroid
增長這三行:ios
export GOROOT=/usr/local/go export PATH=$GOROOT/bin:$PATH export GOPATH=$GOROOT/gocode
使其生效:source /etc/profilegit
4、驗證golang
執行:go versionchrome
go version go1.11.4 linux/amd64
5、Go環境變量介紹json
執行:go envbootstrap
GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/usr/local/go/gocode/" 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=""38六、 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-build119196690=/tmp/go-build -gno-record-gcc-switches"
GOROOT="/usr/local/go" //表示Go在服務器上安裝位置
GOPATH="/usr/local/go/gocode/" //表示Go語言的工做目錄
GOARCH="amd64" //表示機器的處理器架構,值能夠是:38六、amd6四、arm
GOOS="linux" //表示當前機器的操做系統,值能夠是:darwin、freebsd、linux、windows(其中darwin就是mac系統)
GOBIN="" //表示編譯器和連接器的安裝位置,默認位置是 $GOROOT/bin,通常狀況下你能夠將它的值設置爲空,Go 將會使用前面提到的默認值
6、Go語言源碼路徑說明
[root@Go ~]# ls -l /usr/local/go total 180 drwxr-xr-x 2 root root 258 Dec 15 07:36 api -rw-r--r-- 1 root root 55284 Dec 15 07:36 AUTHORS drwxr-xr-x 2 root root 42 Dec 15 07:48 bin -rw-r--r-- 1 root root 1339 Dec 15 07:36 CONTRIBUTING.md -rw-r--r-- 1 root root 71070 Dec 15 07:36 CONTRIBUTORS drwxr-xr-x 8 root root 4096 Dec 15 07:36 doc -rw-r--r-- 1 root root 5686 Dec 15 07:36 favicon.ico drwxr-xr-x 2 root root 6 Jan 23 15:30 gocode drwxr-xr-x 3 root root 18 Dec 15 07:36 lib -rw-r--r-- 1 root root 1479 Dec 15 07:36 LICENSE drwxr-xr-x 15 root root 202 Dec 15 07:48 misc -rw-r--r-- 1 root root 1303 Dec 15 07:36 PATENTS drwxr-xr-x 9 root root 199 Dec 15 07:48 pkg -rw-r--r-- 1 root root 1607 Dec 15 07:36 README.md -rw-r--r-- 1 root root 26 Dec 15 07:36 robots.txt drwxr-xr-x 46 root root 4096 Dec 15 07:36 src drwxr-xr-x 22 root root 8192 Dec 15 07:48 test -rw-r--r-- 1 root root 8 Dec 15 07:36 VERSION
1)bin目錄
-rwxr-xr-x 1 root root 13057654 Dec 15 07:38 go -rwxr-xr-x 1 root root 16006569 Dec 15 07:48 godoc -rwxr-xr-x 1 root root 3373518 Dec 15 07:38 gofmt
包含可執行文件,如:編輯器、Go工具
2)doc目錄
drwxr-xr-x 3 root root 85 Dec 15 07:36 articles -rw-r--r-- 1 root root 33541 Dec 15 07:36 asm.html -rw-r--r-- 1 root root 3006 Dec 15 07:36 cmd.html -rw-r--r-- 1 root root 16933 Dec 15 07:36 code.html drwxr-xr-x 2 root root 202 Dec 15 07:46 codewalk -rw-r--r-- 1 root root 8701 Dec 15 07:36 conduct.html -rw-r--r-- 1 root root 4586 Dec 15 07:36 contrib.html -rw-r--r-- 1 root root 36834 Dec 15 07:36 contribute.html -rw-r--r-- 1 root root 16577 Dec 15 07:36 debugging_with_gdb.html drwxr-xr-x 2 root root 65 Dec 15 07:36 devel -rw-r--r-- 1 root root 17573 Dec 15 07:36 diagnostics.html -rw-r--r-- 1 root root 8865 Dec 15 07:36 docs.html -rw-r--r-- 1 root root 1405 Dec 15 07:36 editors.html -rw-r--r-- 1 root root 116452 Dec 15 07:36 effective_go.html -rw-r--r-- 1 root root 4319 Dec 15 07:36 gccgo_contribute.html -rw-r--r-- 1 root root 17052 Dec 15 07:36 gccgo_install.html -rw-r--r-- 1 root root 59265 Dec 15 07:36 go1.10.html -rw-r--r-- 1 root root 36305 Dec 15 07:36 go1.11.html -rw-r--r-- 1 root root 40411 Dec 15 07:36 go1.1.html -rw-r--r-- 1 root root 35000 Dec 15 07:36 go1.2.html -rw-r--r-- 1 root root 23115 Dec 15 07:36 go1.3.html -rw-r--r-- 1 root root 33535 Dec 15 07:36 go1.4.html -rw-r--r-- 1 root root 47800 Dec 15 07:36 go1.5.html -rw-r--r-- 1 root root 37592 Dec 15 07:36 go1.6.html -rw-r--r-- 1 root root 43702 Dec 15 07:36 go1.7.html -rw-r--r-- 1 root root 59014 Dec 15 07:36 go1.8.html -rw-r--r-- 1 root root 37538 Dec 15 07:36 go1.9.html -rw-r--r-- 1 root root 7216 Dec 15 07:36 go1compat.html -rw-r--r-- 1 root root 71461 Dec 15 07:36 go1.html -rw-r--r-- 1 root root 89479 Dec 15 07:36 go_faq.html -rw-r--r-- 1 root root 8843 Dec 15 07:36 go-logo-black.png -rw-r--r-- 1 root root 9360 Dec 15 07:36 go-logo-blue.png -rw-r--r-- 1 root root 21469 Dec 15 07:36 go-logo-white.png -rw-r--r-- 1 root root 13497 Dec 15 07:36 go_mem.html drwxr-xr-x 3 root root 4096 Dec 15 07:36 gopher -rw-r--r-- 1 root root 204825 Dec 15 07:36 go_spec.html -rw-r--r-- 1 root root 3128 Dec 15 07:36 help.html -rw-r--r-- 1 root root 34 Dec 15 07:36 ie.css -rw-r--r-- 1 root root 9159 Dec 15 07:36 install.html -rw-r--r-- 1 root root 19777 Dec 15 07:36 install-source.html drwxr-xr-x 2 root root 131 Dec 15 07:36 play drwxr-xr-x 2 root root 4096 Dec 15 07:36 progs -rw-r--r-- 1 root root 4520 Dec 15 07:36 root.html -rw-r--r-- 1 root root 8411 Dec 15 07:36 security.html -rw-r--r-- 1 root root 2993 Dec 15 07:36 share.png -rw-r--r-- 1 root root 360 Dec 15 07:36 tos.html
包含示例程序、代碼工具、本地文檔等
3)lib目錄
[root@Go go]# ls -l lib/ drwxr-xr-x 2 root root 59 Jan 24 17:33 time [root@Go go]# ls -l lib/time/ -rw-r--r-- 1 root root 378 Dec 15 07:36 README -rwxr-xr-x 1 root root 1367 Dec 15 07:36 update.bash -rw-r--r-- 1 root root 365101 Dec 15 07:36 zoneinfo.zip
包含文檔模板
4)misc目錄
drwxr-xr-x 2 root root 64 Dec 15 07:36 android drwxr-xr-x 2 root root 15 Dec 15 07:36 arm -rwxr-xr-x 1 root root 110 Dec 15 07:36 benchcmp drwxr-xr-x 20 root root 4096 Dec 15 07:36 cgo drwxr-xr-x 3 root root 24 Dec 15 07:36 chrome -rw-r--r-- 1 root root 159 Dec 15 07:36 editors drwxr-xr-x 2 root root 24 Dec 15 07:36 git drwxr-xr-x 2 root root 86 Dec 15 07:36 ios drwxr-xr-x 2 root root 26 Dec 15 07:36 linkcheck drwxr-xr-x 3 root root 150 Dec 15 07:36 nacl drwxr-xr-x 2 root root 23 Dec 15 07:36 sortac drwxr-xr-x 4 root root 35 Dec 15 07:36 swig drwxr-xr-x 7 root root 79 Dec 15 07:48 tour drwxr-xr-x 2 root root 53 Dec 15 07:36 trace drwxr-xr-x 2 root root 71 Dec 15 07:36 wasm
包含與支持Go編輯器有關的配置文件以及cgo的示例
5)src目錄
-rwxr-xr-x 1 root root 407 Dec 15 07:36 all.bash -rw-r--r-- 1 root root 726 Dec 15 07:36 all.bat -rwxr-xr-x 1 root root 385 Dec 15 07:36 all.rc -rwxr-xr-x 1 root root 2622 Dec 15 07:36 androidtest.bash drwxr-xr-x 4 root root 28 Dec 15 07:36 archive -rwxr-xr-x 1 root root 3738 Dec 15 07:36 bootstrap.bash drwxr-xr-x 2 root root 123 Dec 15 07:36 bufio -rwxr-xr-x 1 root root 1818 Dec 15 07:36 buildall.bash drwxr-xr-x 2 root root 24 Dec 15 07:36 builtin drwxr-xr-x 2 root root 234 Dec 15 07:36 bytes -rwxr-xr-x 1 root root 521 Dec 15 07:36 clean.bash -rw-r--r-- 1 root root 565 Dec 15 07:36 clean.bat -rwxr-xr-x 1 root root 380 Dec 15 07:36 clean.rc drwxr-xr-x 24 root root 289 Dec 15 07:36 cmd -rw-r--r-- 1 root root 1519 Dec 15 07:36 cmp.bash drwxr-xr-x 8 root root 83 Dec 15 07:36 compress drwxr-xr-x 5 root root 42 Dec 15 07:36 container drwxr-xr-x 2 root root 131 Dec 15 07:36 context drwxr-xr-x 20 root root 275 Dec 15 07:36 crypto drwxr-xr-x 3 root root 17 Dec 15 07:36 database drwxr-xr-x 8 root root 82 Dec 15 07:36 debug drwxr-xr-x 13 root root 161 Dec 15 07:36 encoding drwxr-xr-x 2 root root 68 Dec 15 07:36 errors drwxr-xr-x 2 root root 45 Dec 15 07:36 expvar drwxr-xr-x 2 root root 115 Dec 15 07:36 flag drwxr-xr-x 2 root root 176 Dec 15 07:36 fmt drwxr-xr-x 14 root root 173 Dec 15 07:36 go drwxr-xr-x 6 root root 201 Dec 15 07:36 hash drwxr-xr-x 3 root root 151 Dec 15 07:36 html drwxr-xr-x 9 root root 4096 Dec 15 07:36 image drwxr-xr-x 3 root root 33 Dec 15 07:36 index drwxr-xr-x 12 root root 194 Dec 15 07:36 internal drwxr-xr-x 3 root root 146 Dec 15 07:36 io -rwxr-xr-x 1 root root 2116 Dec 15 07:36 iostest.bash drwxr-xr-x 3 root root 76 Dec 15 07:36 log -rwxr-xr-x 1 root root 6339 Dec 15 07:36 make.bash -rw-r--r-- 1 root root 3946 Dec 15 07:36 make.bat -rw-r--r-- 1 root root 553 Dec 15 07:36 Make.dist -rwxr-xr-x 1 root root 3136 Dec 15 07:36 make.rc drwxr-xr-x 6 root root 8192 Dec 15 07:36 math drwxr-xr-x 5 root root 4096 Dec 15 07:36 mime -rwxr-xr-x 1 root root 1255 Dec 15 07:36 naclmake.bash -rwxr-xr-x 1 root root 1216 Dec 15 07:36 nacltest.bash drwxr-xr-x 10 root root 8192 Dec 15 07:36 net drwxr-xr-x 5 root root 4096 Dec 15 07:39 os drwxr-xr-x 3 root root 117 Dec 15 07:36 path drwxr-xr-x 2 root root 70 Dec 15 07:36 plugin -rwxr-xr-x 1 root root 976 Dec 15 07:36 race.bash -rw-r--r-- 1 root root 1037 Dec 15 07:36 race.bat drwxr-xr-x 2 root root 4096 Dec 15 07:36 reflect drwxr-xr-x 4 root root 232 Dec 15 07:36 regexp -rwxr-xr-x 1 root root 1681 Dec 15 07:36 run.bash -rw-r--r-- 1 root root 1147 Dec 15 07:36 run.bat -rwxr-xr-x 1 root root 418 Dec 15 07:36 run.rc drwxr-xr-x 10 root root 16384 Dec 15 07:36 runtime drwxr-xr-x 2 root root 334 Dec 15 07:36 sort drwxr-xr-x 3 root root 4096 Dec 15 07:36 strconv drwxr-xr-x 2 root root 333 Dec 15 07:36 strings drwxr-xr-x 3 root root 4096 Dec 15 07:36 sync drwxr-xr-x 3 root root 12288 Dec 15 07:36 syscall drwxr-xr-x 5 root root 335 Dec 15 07:36 testing drwxr-xr-x 5 root root 54 Dec 15 07:36 text drwxr-xr-x 2 root root 4096 Dec 15 07:36 time drwxr-xr-x 4 root root 252 Dec 15 07:36 unicode drwxr-xr-x 2 root root 23 Dec 15 07:36 unsafe drwxr-xr-x 3 root root 24 Dec 15 07:36 vendor
包含源代碼構建腳本和標準庫的包的完整源代碼
6)src/cmd目錄
drwxr-xr-x 2 root root 46 Dec 15 07:36 addr2line drwxr-xr-x 3 root root 73 Dec 15 07:36 api drwxr-xr-x 3 root root 51 Dec 15 07:36 asm drwxr-xr-x 2 root root 38 Dec 15 07:36 buildid drwxr-xr-x 2 root root 130 Dec 15 07:36 cgo drwxr-xr-x 3 root root 87 Dec 15 07:36 compile drwxr-xr-x 3 root root 121 Dec 15 07:41 cover drwxr-xr-x 2 root root 4096 Dec 15 07:38 dist drwxr-xr-x 3 root root 85 Dec 15 07:36 doc drwxr-xr-x 2 root root 4096 Dec 15 07:36 fix drwxr-xr-x 4 root root 258 Dec 15 07:43 go drwxr-xr-x 3 root root 149 Dec 15 07:36 gofmt drwxr-xr-x 15 root root 178 Dec 15 07:36 internal drwxr-xr-x 3 root root 115 Dec 15 07:36 link drwxr-xr-x 2 root root 73 Dec 15 07:36 nm drwxr-xr-x 3 root root 60 Dec 15 07:36 objdump drwxr-xr-x 2 root root 55 Dec 15 07:36 pack drwxr-xr-x 2 root root 71 Dec 15 07:36 pprof drwxr-xr-x 2 root root 21 Dec 15 07:36 test2json drwxr-xr-x 2 root root 184 Dec 15 07:36 trace drwxr-xr-x 4 root root 95 Dec 15 07:36 vendor drwxr-xr-x 5 root root 4096 Dec 15 07:41 vet
包含Go和C的編輯器和命令行腳本