方式一:yum安装(最简单)
1
2
|
rpm
-
Uvh
http
:
//dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum
install
golang
|
方式二:源码安装:
1
2
3
4
5
6
7
8
9
10
|
wget
http
:
//go.googlecode.com/files/go1.2.linux-amd64.tar.gz
tar
-
xvf
go1
.
2.linux
-
amd64
.
tar
.
gz
sudo
cp
-
r
go
/
usr
/
local
/
go
vi
/
etc
/
profile
export
GOROOT
=
/
usr
/
local
/
go
export
PATH
=
$
PATH
:
$
GOROOT
/
bin
source
/
etc
/
profile
|
方式三:类似源码安装
1
2
3
4
5
6
7
|
1.
$
sudo
yum
install
mercurial
2.
$
hg
clone
-
u
release
https
:
//go.googlecode.com/hg/ golang
3.
To
build
the
Go
distribution
,
run
$
cd
go
/
src
$
.
/
all
.
bash
4.
If
all
goes
well
,
it
will
finish
by
printing
output
like
:
ALL
TESTS
PASSED
--
-
Installed
Go
for
linux
/
amd64
in
/
home
/
you
/
go
.
Installed
commands
in
/
home
/
you
/
go
/
bin
.
*
*
*
You
need
to
add
/
home
/
you
/
go
/
bin
to
your
$
PATH
.
*
*
*
|
安装完毕之后看看状态:
1
2
|
$
go
version
go
version
go1
.
2
linux
/
amd64
|
测试文件
1
2
3
4
5
6
7
|
cat
hello
.
go
package
main
import
"fmt"
func
main
(
)
{
fmt
.
Printf
(
"what's up, sudops.com\n"
)
}
|
# go env 查看详细信息
GOARCH="686"
GOBIN="/usr/lib/golang/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -fmessage-length=0"
CXX="g++"
CGO_ENABLED="0"