Linux下64 位元 先行編譯 的 go 1.6.2 安裝

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

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
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.