Go-Yum Install Go
使用 yum 安装 Go
1[root@itfranky ~]# cat /etc/redhat-release
2CentOS release 6.5 (Final)
3[root@itfranky ~]# yum -y install go
4[root@itfranky ~]# yum list installed | grep -E '^golang'
5golang.x86_64 1.9.2-1.el6 @epel
6golang-bin.x86_64 1.9.2-1.el6 @epel
7golang-src.noarch 1.9.2-1.el6 @epel
8[root@itfranky ~]#
9[root@itfranky ~]# go version
10go version go1.9.2 linux/amd64
11[root@itfranky ~]# go env
12GOARCH="amd64"
13GOBIN=""
14GOEXE=""
15GOHOSTARCH="amd64"
16GOHOSTOS="linux"
17GOOS="linux"
18GOPATH="/root/go"
19GORACE=""
20GOROOT="/usr/lib/golang"
21GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
22GCCGO="gccgo"
23CC="gcc"
24GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build734280670=/tmp/go-build"
25CXX="g++"
26CGO_ENABLED="1"
27CGO_CFLAGS="-g -O2"
28CGO_CPPFLAGS=""
29CGO_CXXFLAGS="-g -O2"
30CGO_FFLAGS="-g -O2"
31CGO_LDFLAGS="-g -O2"
32PKG_CONFIG="pkg-config"
33[root@itfranky ~]#
设置环境变量
GOROOT
该环境变量的值为GO语言的当前安装目录,yum安装在/usr/lib/golang
目录下。
GOPATH
Go语言的工作区集合,如:$HOME/franky/GoProject
GOBIN
存放Go程序的可执行文件的目录,如:/app/gobin
PATH
Go语言命令和Go程序的可执行文件,需要追加其值PATH=$PATH:$GOBIN
yum安装已经设置了Go语言命令的快捷方式,PATH追加Go程序的可执行文件即可。
1[root@itfranky ~]# ls /usr/bin/go -ltr
2lrwxrwxrwx 1 root root 20 Jan 11 20:07 /usr/bin/go -> /etc/alternatives/go
3[root@itfranky ~]#
4[root@itfranky ~]# ls /etc/alternatives/go -ltr
5lrwxrwxrwx 1 root root 22 Jan 11 20:07 /etc/alternatives/go -> /usr/lib/golang/bin/go
6[root@itfranky ~]#
7[root@itfranky ~]#
编辑/etc/profile文件
追加:
1#set go environment
2
3export GOPATH=$HOME/franky/GoProject
4export GOBIN=/app/gobin
5export PATH=$PATH:$GOBIN
然后执行 source /etc/profile 使之生效。
1[root@itfranky franky]# mkdir -p /app/gobin
2[root@itfranky franky]# mkdir -p ~/franky/GoProject
3[root@itfranky franky]# source /etc/profile
4[root@itfranky franky]# go env
5GOARCH="amd64"
6GOBIN="/app/gobin"
7GOEXE=""
8GOHOSTARCH="amd64"
9GOHOSTOS="linux"
10GOOS="linux"
11GOPATH="/root/franky/GoProject"
12GORACE=""
13GOROOT="/usr/lib/golang"
14GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
15GCCGO="gccgo"
16CC="gcc"
17GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build059348698=/tmp/go-build"
18CXX="g++"
19CGO_ENABLED="1"
20CGO_CFLAGS="-g -O2"
21CGO_CPPFLAGS=""
22CGO_CXXFLAGS="-g -O2"
23CGO_FFLAGS="-g -O2"
24CGO_LDFLAGS="-g -O2"
25PKG_CONFIG="pkg-config"
26[root@itfranky franky]# go version
27go version go1.9.2 linux/amd64
28[root@itfranky franky]#