網上講go語言編譯環境搭建的文章不少了,搭建環境本身也相對簡單,
本文主要是提供一個可下載的地址,因為剛開始我找了好幾個地址都沒能下載到想要的版本,
這個地址是剛(2013.04.08晚)試過能訪問的:http://code.google.com/p/go/downloads/list
Downloads頁面有下面這些go語言開發包,這里我們選擇下載go1.0.3.windows-386.zip:
go1.0.3.darwin-386-signed.pkg | ||
如果上面地址不能下了,請到我的微盤下載:go1.0.3.windows-386.zip go1.0.3.linux-386.tar.gz
下載下來之后go環境的配置比較簡單:
1 解壓壓縮包到go工作目錄,如解壓到E:\opensource\go\go,解壓后的目錄結構如下:
E:\opensource\go\go
├─api
├─bin
│ ├─go.exe
│ ├─godoc.exe
│ └─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
2 增加環境變量GOROOT,取值為上面的go工作目錄
3 Path環境變量中添加";%GOROOT%\bin",以便能夠直接調用go命令來編譯go代碼,至此go編譯環境就配置好了
注:如果不想手動設置系統環境變量,也可下載go啟動環境批處理附件,
修改goenv.bat文件中的GOROOT值為上面的go工作目錄后直接雙擊該bat文件,go編譯環境變量即設置完成。
4 測試go編譯環境,啟動一個cmd窗口,直接輸入go,看到下面的提示就是搭建成功了
E:\opensource\go\go>go Go is a tool for managing Go source code. Usage: go command [arguments] The commands are: build compile packages and dependencies clean remove object files doc run godoc on package sources env print Go environment information fix run go tool fix on packages fmt run gofmt on package sources get download and install packages and dependencies install compile and install packages and dependencies list list packages run compile and run Go program test test packages tool run specified go tool version print Go version vet run go tool vet on packages Use "go help [command]" for more information about a command. Additional help topics: gopath GOPATH environment variable packages description of package lists remote remote import path syntax testflag description of testing flags testfunc description of testing functions Use "go help [topic]" for more information about that topic.
5 編譯helloworld測試程序,go語言包中test目錄帶有helloworld.go測試程序,源碼見"附一 helloworld.go",
直接調用"go build helloworld.go"就生成了"helloworld.exe"可執行程序,運行一下這個程序看到了我們期望的hello,wolrd。
E:\opensource\go\go\test>go build helloworld.go E:\opensource\go\go\test>helloworld.exe hello, world E:\opensource\go\go\test>
// cmpout // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that we can do page 1 of the C book. package main func main() { print("hello, world\n") }
修改歷史:
2013.04.08 初稿
2013.04.09 增加go語言系統環境自動設置附件
2013.04.10 增加go語言開發包微盤下載地址