Linux下64 位 预编译 的 go 1.6.2 安装
2016-06-06 15:33
726 查看
go 安装 - 1.6.2
OS: Linux, 64位, readhat 7.2
使用官网预编译gz包安装
1. 网址 https://golang.org/ 目前版本 1.6.2
下载页 https://golang.org/dl/ https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
2. 解压缩
go要求ROOT
目录在 /usr/local 下,解压命令:
[root@ip-172-30-0-110 home]# tar -C /usr/local -xf go1.6.2.linux-amd64.tar.gz
[root@ip-172-30-0-110 home]# ls /usr/local/
bin etc games go include lib lib64 libexec sbin share src
3. 修改/etc/profile 添加如下:
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
source /etc/profile
测试
[root@ip-172-30-0-110 go]# which go
/usr/local/go/bin/go
[root@ip-172-30-0-110 go]# go version
go version go1.6.2 linux/amd64
[root@ip-172-30-0-110 go]#
4. 运行helloworld程序
hello.go内容
package main
import "fmt"
func main() {
fmt.Printf("Hello world!\n");
}
编译运行
[root@ip-172-30-0-110 go]# vi hello.go
[root@ip-172-30-0-110 go]# go run hello.go
Hello world!
[root@ip-172-30-0-110 go]#
5. 编译hello项目
在当前目录下, 创建目录
[root@ip-172-30-0-110 gopath]# mkdir bin pkg src
[root@ip-172-30-0-110 gopath]# ls
bin pkg src
按照如下方式放置文件
[root@ip-172-30-0-110 gopath]# tree .
.
├── bin
├── pkg
└── src
└── hello
└── hello.go
在当前目录下,编译hello项目
[root@ip-172-30-0-110 gopath]# export GOPATH=`pwd`; go install hello
[root@ip-172-30-0-110 gopath]# tree .
.
├── bin
│ └── hello
├── pkg
└── src
└── hello
└── hello.go
4 directories, 2 files
[root@ip-172-30-0-110 gopath]#
运行可执行文件
[root@ip-172-30-0-110 gopath]# bin/hello
Hello world!
[root@ip-172-30-0-110 gopath]#
说明:
a) go在两个地方找程序包
$GOROOT 下的src目录, 以及 $GOPATH 下的src 目录
报错示例如下:
[root@ip-172-30-0-110 gopath]# go install hello.go
go install: no install location for .go files listed on command line (GOBIN not set)
[root@ip-172-30-0-110 gopath]# go install hello
can't load package: package hello: cannot find package "hello" in any of:
/usr/local/go/src/hello (from $GOROOT)
($GOPATH not set)
b)项目的名字可以更换,
如将 src/hello, 更改为test, 那么项目的名字,也就变成了 test, 如使用go build 命令,变如下:
[root@ip-172-30-0-110 gopath]# go build test
[root@ip-172-30-0-110 gopath]# ls -alht
total 2.2M
drwxr-xr-x 5 root root 47 Jun 6 03:01 .
-rwxr-xr-x 1 root root 2.2M Jun 6 03:01 test
drwxr-xr-x 2 root root 17 Jun 6 03:00 bin
drwxr-xr-x 3 root root 17 Jun 6 02:54 src
drwxr-xr-x 2 root root 6 Jun 6 02:43 pkg
drwxr-xr-x. 7 root root 4.0K Jun 6 02:41 ..
[root@ip-172-30-0-110 gopath]#
目录结构
.
├── bin
├── pkg
├── src
│ └── test
│ └── hello.go
└── test
6. mercurial工具
yum install mercurial
OS: Linux, 64位, readhat 7.2
使用官网预编译gz包安装
1. 网址 https://golang.org/ 目前版本 1.6.2
下载页 https://golang.org/dl/ https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
2. 解压缩
go要求ROOT
目录在 /usr/local 下,解压命令:
[root@ip-172-30-0-110 home]# tar -C /usr/local -xf go1.6.2.linux-amd64.tar.gz
[root@ip-172-30-0-110 home]# ls /usr/local/
bin etc games go include lib lib64 libexec sbin share src
3. 修改/etc/profile 添加如下:
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
source /etc/profile
测试
[root@ip-172-30-0-110 go]# which go
/usr/local/go/bin/go
[root@ip-172-30-0-110 go]# go version
go version go1.6.2 linux/amd64
[root@ip-172-30-0-110 go]#
4. 运行helloworld程序
hello.go内容
package main
import "fmt"
func main() {
fmt.Printf("Hello world!\n");
}
编译运行
[root@ip-172-30-0-110 go]# vi hello.go
[root@ip-172-30-0-110 go]# go run hello.go
Hello world!
[root@ip-172-30-0-110 go]#
5. 编译hello项目
在当前目录下, 创建目录
[root@ip-172-30-0-110 gopath]# mkdir bin pkg src
[root@ip-172-30-0-110 gopath]# ls
bin pkg src
按照如下方式放置文件
[root@ip-172-30-0-110 gopath]# tree .
.
├── bin
├── pkg
└── src
└── hello
└── hello.go
在当前目录下,编译hello项目
[root@ip-172-30-0-110 gopath]# export GOPATH=`pwd`; go install hello
[root@ip-172-30-0-110 gopath]# tree .
.
├── bin
│ └── hello
├── pkg
└── src
└── hello
└── hello.go
4 directories, 2 files
[root@ip-172-30-0-110 gopath]#
运行可执行文件
[root@ip-172-30-0-110 gopath]# bin/hello
Hello world!
[root@ip-172-30-0-110 gopath]#
说明:
a) go在两个地方找程序包
$GOROOT 下的src目录, 以及 $GOPATH 下的src 目录
报错示例如下:
[root@ip-172-30-0-110 gopath]# go install hello.go
go install: no install location for .go files listed on command line (GOBIN not set)
[root@ip-172-30-0-110 gopath]# go install hello
can't load package: package hello: cannot find package "hello" in any of:
/usr/local/go/src/hello (from $GOROOT)
($GOPATH not set)
b)项目的名字可以更换,
如将 src/hello, 更改为test, 那么项目的名字,也就变成了 test, 如使用go build 命令,变如下:
[root@ip-172-30-0-110 gopath]# go build test
[root@ip-172-30-0-110 gopath]# ls -alht
total 2.2M
drwxr-xr-x 5 root root 47 Jun 6 03:01 .
-rwxr-xr-x 1 root root 2.2M Jun 6 03:01 test
drwxr-xr-x 2 root root 17 Jun 6 03:00 bin
drwxr-xr-x 3 root root 17 Jun 6 02:54 src
drwxr-xr-x 2 root root 6 Jun 6 02:43 pkg
drwxr-xr-x. 7 root root 4.0K Jun 6 02:41 ..
[root@ip-172-30-0-110 gopath]#
目录结构
.
├── bin
├── pkg
├── src
│ └── test
│ └── hello.go
└── test
6. mercurial工具
yum install mercurial
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- 从源码安装Mysql/Percona 5.5
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程