CentOS GO 語言環境的搭建


go 語言源碼安裝依賴 ,gcc ,make glibc庫,等,上述工具安裝省略,

這個是官方地址:http://www.golang.org/

另外,其源代碼更新采用的是mercurial 工具,安裝前先安裝mercureal :

1.mercurial安裝使用

yum install mercurial

2.設置環境變量在.bash_profile中
#go set
export GOROOT=/usr/local/go
export GOOS=linux
export GOARCH=386
export GOBIN=$GOROOT/bin

PATH=$PATH:$GOBIN
export PATH
alias cdg="cd /project/go"
-------------------------------------

注意:新版本的好像不一樣了,要單獨設置GOROOT目錄和GOPATH目錄,可以理解為

一個是環境目錄

一個是編譯執行的目錄

所以上面的例子要修改一下

export GOROOT=/usr/local/go

export GOPATH=/home/jackluo/go
export GOOS=linux
export GOARCH=386
export GOBIN=$GOROOT/bin

PATH=$PATH:$GOBIN

---------------

這樣就不會報

warning: GOPATH set to GOROOT (/home/jackluo/go) has no effect這樣的錯了

2.下載go安裝包:
hg clone -r release https://go.googlecode.com/hg/ $GOROOT
cd $GOROOT/src && ./all.bash

3.運行go  看是否能找到命令


4.編寫demo程序驗證下:

1.編寫demo程序:

  demo.go
 
package main
import "fmt"


func main() {
    fmt.Printf("Let's go\n")
}

1>編譯運行:
  go run demo.go

運行:
./demo

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM