找到最新golang 安装包 https://dl.gocn.io/
mkdir /opt/go
cd /opt/go
vim go_install.sh
wget -c https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz
#把golang的bin目录加入全局环境变量
cat >>/etc/profile<<EOF
export PATH=$PATH:/usr/local/go/bin
EOF
#让配置生效
source /etc/profile
#检查下是否成功
go version
#在当前用户目录下新建go目录作为项目目录
mkdir -p $HOME/go
#用cat的方法在尾部增加配置配置golang的 GOROOT GOPATH
cat >>$HOME/.bash_profile<<EOF
export GOROOT=/usr/local/go
export GOPATH=\$HOME/go
export PATH=\$PATH:\$GOROOT/bin
EOF
#让配置生效
source $HOME/.bash_profile
#检查下go的env环境变量
go env
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#source go_install.sh //运行后,自动下载并安装
1
[root@go-dev opt]# source ./go_install.sh
--2019-06-08 02:10:43-- https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 203.208.41.66, 203.208.41.67, 203.208.41.68, ...
Connecting to dl.google.com (dl.google.com)|203.208.41.66|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 127938445 (122M) [application/octet-stream]
Saving to: ‘go1.12.5.linux-amd64.tar.gz’
100%[===========================================>] 127,938,445 10.8MB/s in 12s
2019-06-08 02:10:56 (10.0 MB/s) - ‘go1.12.5.linux-amd64.tar.gz’ saved [127938445/127938445]
go version go1.12.5 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build134686822=/tmp/go-build -gno-record-gcc-switches"
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
35
36
37
38
39
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
35
36
37
38
39
参考:http://www.iamle.com/archives/1648.html
在安装过程中,发现golang 1.12.2 版本需要内核 2.6.32 以上(包含)支持。不然会提示
FATAL: kernel too old
升级golang 1.12.2版本步骤:
wget -c https://studygolang.com/dl/golang/go1.12.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.12.2.linux-amd64.tar.gz
1
2
2