目录
一、源码安装
1.设置Go的环境变量
2.下载源码包
3.安装Go
如果出现异常
正常安装 ,输出如下日志, 安装耗时还是比较长的,请耐心等待
4.设置环境变量
5.设置工作目录
6. go 1.13版本得GOPROXY 配置
GOROOT_BOOTSTRAP 这个目录在安装 Go 1.5 版本及之后的版本时需要设置。由于在 1.4 版本后,Go 编译器实现了自举,即通过 1.4 版本来编译安装之后版本的编译器。如果不设置该环境变量的话,会产生这样一个错误“Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.”。
#更多下载: https://github.com/golang/go/releases
# 下载源码包
cd /usr/local
wget https://storage.googleapis.com/golang/go1.4-bootstrap-20170531.tar.gz
tar -xf go1.4-bootstrap-20170531.tar.gz
mv go go1.4
# 安装
cd go1.4/src
./make.bash
vi /etc/profile
# 添加:
export GOROOT_BOOTSTRAP=/usr/local/go1.4
source /etc/profile
cd /usr/local
wget https://github.com/golang/go/archive/go1.12.5.tar.gz
tar -xf go1.12.5.tar.gz
git clone https://github.com/golang/go
git branch -a
# 切换到指定版本
git checkout release-branch.go1.14
这个需要几分钟时间编译
mv go-go1.12 go
cd go/src
./all.bash
go tool dist: FAILED: /usr/local/go1.4/bin/go install -gcflags=-l -tags=math_big_pure_go compiler_bootstrap bootstrap/cmd/...: exit status 1
可能是内存不足, 编译需要至少1G可用的内存吧。
1.10版本编译的时候对内存要求不高。 在编译1.12.x 时候 会出现内存要求
# ./all.bash
Building Go cmd/dist using /usr/local/go1.4.
Building Go toolchain1 using /usr/local/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/amd64.
##### Testing packages.
ok archive/tar 0.014s
ok archive/zip 1.273s
ok bufio 0.030s
ok bytes 0.119s
ok compress/bzip2 0.044s
ok compress/flate 0.560s
ok compress/gzip 0.007s
ok compress/lzw 0.004s
ok compress/zlib 0.015s
ok container/heap 0.006s
ok container/list 0.003s
ok container/ring 0.011s
ok context 0.979s
ok crypto 0.001s
ok crypto/aes 0.020s
ok crypto/cipher 0.084s
ok crypto/des 0.005s
ok crypto/dsa 0.002s
ok crypto/ecdsa 0.094s
ok crypto/elliptic 0.535s
ok crypto/hmac 0.002s
ok crypto/internal/subtle 0.002s
ok crypto/md5 0.002s
ok crypto/rand 0.018s
ok crypto/rc4 0.021s
ok crypto/rsa 0.048s
ok crypto/sha1 0.014s
ok crypto/sha256 0.002s
ok crypto/sha512 0.002s
ok crypto/subtle 0.009s
ok crypto/tls 0.812s
ok crypto/x509 0.667s
ok database/sql 0.537s
ok database/sql/driver 0.001s
ok debug/dwarf 0.015s
ok debug/elf 0.008s
ok debug/gosym 0.169s
ok debug/macho 0.002s
ok debug/pe 0.004s
ok debug/plan9obj 0.002s
ok encoding/ascii85 0.004s
ok encoding/asn1 0.002s
ok encoding/base32 0.012s
ok encoding/base64 0.004s
ok encoding/binary 0.002s
ok encoding/csv 0.003s
ok encoding/gob 0.018s
ok encoding/hex 0.002s
ok encoding/json 0.252s
ok encoding/pem 0.007s
ok encoding/xml 0.010s
ok errors 0.002s
ok expvar 0.003s
ok flag 0.002s
ok fmt 0.063s
ok go/ast 0.003s
ok go/build 0.055s
ok go/constant 0.002s
ok go/doc 0.023s
ok go/format 0.004s
ok go/importer 0.046s
ok go/internal/gccgoimporter 0.005s
ok go/internal/gcimporter 0.168s
ok go/internal/srcimporter 0.744s
ok go/parser 0.013s
ok go/printer 0.223s
ok go/scanner 0.002s
ok go/token 0.012s
ok go/types 0.467s
ok hash 0.002s
ok hash/adler32 0.005s
ok hash/crc32 0.005s
ok hash/crc64 0.002s
ok hash/fnv 0.002s
ok html 0.002s
ok html/template 0.022s
ok image 0.046s
ok image/color 0.013s
ok image/draw 0.032s
ok image/gif 0.440s
ok image/jpeg 0.140s
ok image/png 0.034s
ok index/suffixarray 0.003s
ok internal/cpu 0.005s
ok internal/fmtsort 0.002s
ok internal/poll 0.018s
ok internal/singleflight 0.013s
ok internal/trace 1.074s
ok internal/x/crypto/chacha20poly1305 0.029s
ok internal/x/crypto/cryptobyte 0.002s
ok internal/x/crypto/curve25519 0.012s
ok internal/x/crypto/hkdf 0.002s
ok internal/x/crypto/internal/chacha20 0.031s
ok internal/x/crypto/poly1305 0.005s
ok internal/x/net/dns/dnsmessage 0.032s
ok internal/x/net/http/httpguts 0.002s
ok internal/x/net/http/httpproxy 0.003s
ok internal/x/net/http2/hpack 0.003s
ok internal/x/net/idna 0.002s
ok internal/x/net/nettest 1.115s
ok internal/x/text/transform 0.002s
ok internal/x/text/unicode/norm 0.002s
ok internal/xcoff 0.005s
ok io 0.023s
ok io/ioutil 0.003s
ok log 0.002s
ok log/syslog 2.019s
ok math 0.003s
ok math/big 1.459s
ok math/bits 0.002s
ok math/cmplx 0.002s
ok math/rand 0.242s
ok mime 0.004s
ok mime/multipart 0.250s
ok mime/quotedprintable 0.065s
ok net 3.677s
ok net/http 12.028s
ok net/http/cgi 0.222s
ok net/http/cookiejar 0.004s
ok net/http/fcgi 0.004s
ok net/http/httptest 0.011s
ok net/http/httptrace 0.002s
ok net/http/httputil 0.021s
ok net/http/internal 0.002s
ok net/http/pprof 2.007s
ok net/internal/socktest 0.002s
ok net/mail 0.003s
ok net/rpc 0.019s
ok net/rpc/jsonrpc 0.004s
ok net/smtp 0.007s
ok net/textproto 0.002s
ok net/url 0.004s
ok os 1.119s
ok os/exec 0.436s
ok os/signal 5.480s
ok os/user 0.003s
ok path 0.002s
ok path/filepath 0.022s
ok plugin 0.002s
ok reflect 0.098s
ok regexp 0.037s
ok regexp/syntax 0.244s
ok runtime 24.736s
ok runtime/debug 0.021s
ok runtime/internal/atomic 0.053s
ok runtime/internal/math 0.001s
ok runtime/internal/sys 0.002s
ok runtime/pprof 7.189s
ok runtime/pprof/internal/profile 0.002s
ok runtime/trace 3.030s
ok sort 0.045s
ok strconv 0.306s
ok strings 0.094s
ok sync 0.170s
ok sync/atomic 0.013s
ok syscall 2.220s
ok testing 0.882s
ok testing/quick 0.060s
ok text/scanner 0.003s
ok text/tabwriter 0.002s
ok text/template 0.184s
ok text/template/parse 0.004s
ok time 2.573s
ok unicode 0.002s
ok unicode/utf16 0.002s
ok unicode/utf8 0.003s
ok cmd/addr2line 1.091s
ok cmd/api 0.007s
ok cmd/asm/internal/asm 0.388s
ok cmd/asm/internal/lex 0.002s
ok cmd/compile 0.003s
ok cmd/compile/internal/gc 6.318s
ok cmd/compile/internal/ssa 0.320s
ok cmd/compile/internal/syntax 0.005s
ok cmd/compile/internal/test 0.002s [no tests to run]
ok cmd/compile/internal/types 0.002s
ok cmd/cover 2.046s
ok cmd/doc 0.024s
ok cmd/fix 1.927s
ok cmd/go 117.141s
ok cmd/go/internal/cache 0.181s
ok cmd/go/internal/dirhash 0.002s
ok cmd/go/internal/generate 0.005s
ok cmd/go/internal/get 0.006s
ok cmd/go/internal/imports 0.003s
ok cmd/go/internal/load 0.004s
ok cmd/go/internal/lockedfile 0.035s
ok cmd/go/internal/lockedfile/internal/filelock 0.045s
ok cmd/go/internal/modconv 0.007s
ok cmd/go/internal/modfetch 0.008s
ok cmd/go/internal/modfetch/codehost 0.002s
ok cmd/go/internal/modfile 0.004s
ok cmd/go/internal/modload 0.008s
ok cmd/go/internal/module 0.003s
ok cmd/go/internal/mvs 0.003s
ok cmd/go/internal/par 0.008s
ok cmd/go/internal/search 0.003s
ok cmd/go/internal/semver 0.008s
ok cmd/go/internal/txtar 0.002s
ok cmd/go/internal/web2 0.003s
ok cmd/go/internal/work 0.005s
ok cmd/gofmt 0.024s
ok cmd/internal/buildid 0.115s
ok cmd/internal/dwarf 0.002s
ok cmd/internal/edit 0.002s
ok cmd/internal/goobj 0.247s
ok cmd/internal/obj 0.002s
ok cmd/internal/obj/arm64 0.008s
ok cmd/internal/obj/x86 0.179s
ok cmd/internal/objabi 0.001s
ok cmd/internal/src 0.002s
ok cmd/internal/test2json 0.058s
ok cmd/link 1.561s
ok cmd/link/internal/ld 2.813s
ok cmd/link/internal/sym 0.002s
ok cmd/nm 1.879s
ok cmd/objdump 1.284s
ok cmd/pack 1.214s
ok cmd/trace 0.010s
ok cmd/vendor/github.com/google/pprof/internal/binutils 0.029s
ok cmd/vendor/github.com/google/pprof/internal/driver 0.119s
ok cmd/vendor/github.com/google/pprof/internal/elfexec 0.001s
ok cmd/vendor/github.com/google/pprof/internal/graph 0.003s
ok cmd/vendor/github.com/google/pprof/internal/measurement 0.002s
ok cmd/vendor/github.com/google/pprof/internal/report 0.062s
ok cmd/vendor/github.com/google/pprof/internal/symbolizer 0.003s
ok cmd/vendor/github.com/google/pprof/internal/symbolz 0.003s
ok cmd/vendor/github.com/google/pprof/profile 0.035s
ok cmd/vendor/github.com/ianlancetaylor/demangle 0.010s
ok cmd/vendor/golang.org/x/arch/arm/armasm 0.006s
ok cmd/vendor/golang.org/x/arch/arm64/arm64asm 0.049s
ok cmd/vendor/golang.org/x/arch/ppc64/ppc64asm 0.002s
ok cmd/vendor/golang.org/x/arch/x86/x86asm 0.054s
ok cmd/vendor/golang.org/x/crypto/ssh/terminal 0.003s
ok cmd/vendor/golang.org/x/sys/unix 0.362s
ok cmd/vet 12.593s
##### os/user with tag osusergo
ok os/user 0.025s
##### GOMAXPROCS=2 runtime -cpu=1,2,4 -quick
ok runtime 13.866s
##### cmd/go terminal test
PASS
ok _/usr/local/go/src/cmd/go/testdata/testterminal18153 0.001s
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
No support for static linking found (lacks libc.a?), skip cgo static linking test.
##### Testing without libgcc.
ok crypto/x509 1.657s
ok net 0.037s
ok os/user 0.078s
##### internal linking of -buildmode=pie
ok reflect 2.525s
##### sync -cpu=10
ok sync 0.826s
##### Testing race detector
ok runtime/race 42.842s
ok flag 1.065s
ok net 1.165s
ok os 1.123s
ok os/exec 3.074s
ok encoding/gob 1.031s
PASS
scatter = 0x61da60
hello from C
sqrt is: 0
ok _/usr/local/go/misc/cgo/test 8.562s
ok flag 1.058s
ok os/exec 3.154s
##### ../misc/cgo/stdio
##### ../misc/cgo/life
##### ../misc/cgo/test
PASS
ok _/usr/local/go/misc/cgo/test 10.103s
PASS
ok _/usr/local/go/misc/cgo/test 10.020s
PASS
ok _/usr/local/go/misc/cgo/test 9.250s
PASS
ok _/usr/local/go/misc/cgo/testtls 0.023s
PASS
ok _/usr/local/go/misc/cgo/testtls 0.063s
PASS
ok _/usr/local/go/misc/cgo/test 5.492s
PASS
ok _/usr/local/go/misc/cgo/testtls 0.035s
PASS
ok _/usr/local/go/misc/cgo/nocgo 0.058s
##### ../misc/cgo/testgodefs
##### ../misc/cgo/testso
##### ../misc/cgo/testsovar
##### ../misc/cgo/testcarchive
PASS
##### ../misc/cgo/testcshared
PASS
##### ../misc/cgo/testshared
PASS
ok _/usr/local/go/misc/cgo/testshared 47.559s
##### ../misc/cgo/testplugin
PASS
something
1.5
##### ../misc/cgo/testasan
##### ../misc/cgo/testsanitizers
PASS
##### ../misc/cgo/errors
PASS
##### ../misc/cgo/testsigfwd
##### ../test/bench/go1
testing: warning: no tests to run
PASS
ok _/usr/local/go/test/bench/go1 4.677s
##### ../test
##### API check
Go version is "go1.12.5", ignoring -next /usr/local/go/api/next.txt
ALL TESTS PASSED
---
Installed Go for linux/amd64 in /usr/local/go
Installed commands in /usr/local/go/bin
*** You need to add /usr/local/go/bin to your PATH.
vim /etc/profile
export GOROOT=/usr/local/go
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
export GOPATH=/usr/local/mygo
export PATH=$PATH:${GOPATH//://bin:}/bin
source /etc/profile
go version
配置环境变量
export PATH=$PATH:/usr/local/go/bin
参考: https://github.com/goproxy/goproxy.cn/blob/master/README.zh-CN.md
需要设置环境变量:
$ go env -w GOPROXY=https://goproxy.cn,direct
或者 linux
export GOPROXY=https://goproxy.cn,direct
windows: GOPROXY=https://goproxy.cn,direct
至此,我们的Golang已经安装好了