這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
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.