Golang安裝配置

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

 

1.下載安裝

    地址:https://golang.org/dl/

1.1   linux版本下載:   

wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz --no-check-certificatetar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz

2.工作目錄和環境配置:

 GOROOT 是golang安裝根目錄

 GOPATH 是工作目錄

PATH會設定下 GOROOT和GOPATH bin目錄

vim ~/.bash_profile

export GOROOT=/usr/local/go

export GOPATH=/root/workspace

export PATH=.:$PATH:$GOROOT/bin:$GOPATH/bin

配置成功後  go env 驗證一下環境變數是否配置成功

3.編寫第一個GO程式

    進入$GOPATH/src/hello 目錄下, 目錄不存在建立,建立一個新檔案命名:hello.go   

package mainimport "fmt"func main() {    fmt.Printf("hello, world\n")}

編譯

$ cd $GOAPTH/src/hello$ go build

執行

$ ./hellohello, world

或者直接執行:

go run hello.go

4.開發工具

4.1  liteide安裝

      windows下載:https://golang.org/doc/install?download=go1.9.2.windows-amd64.msi

      下載成功後預設安裝:c:\Go

      a.liteide 官方地址:https://github.com/visualfc/liteide

      b.下載地址:https://sourceforge.net/projects/liteide/

      d.下載成功後解壓得到 liteide 目錄,將其拷貝到 C:/Go(註:預設安裝目錄$GOROOT),

      e.開啟 c:\go\liteide\bin,為 liteide.exe 建立案頭捷徑

      f.雙擊案頭上的 liteide.exe 捷徑開啟 LiteIDE,開啟工具列中的 system 下拉條,選中 win64

       h. 控制台會顯示當前環境變數配置:

      

當前環境變更 id "win64"

Found go bin at c:\go\bin\go.exe

GOROOT=c:\go

GOARCH=amd64

GOOS=windows

   ctrl+N 建立一個新項目

 

Ctrl+b 構建項目

 

5.相關資料

http://blog.csdn.net/defonds/article/details/50544208

 

6.相關問題

6.1 exec: "gcc": executable file not found in %PATH%

解決方案:http://www.cnblogs.com/zsy/p/5958170.html

# github.com/toolkits/sys..\..\..\toolkits\sys\cmd.go:54:9: undefined: syscall.Kill# github.com/open-falcon/rrdliteexec: "gcc": executable file not found in %PATH%錯誤: 進程結束代碼 2.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.