1、下載 golang 並解壓(這裡以解壓到 $HOME/golang/ 目錄為例):http://www.golangtc.com/download2、建立 GoPath 相關目錄(這裡以 $HOME/golang/projects/ 目錄為例):mkdir ~/golangmkdir ~/golang/projectsmkdir ~/golang/projects/3rdpartymkdir ~/golang/projects/3rdparty/binmkdir ~/golang/projects/3rdparty/pkgmkdir ~/golang/projects/3rdparty/srcmkdir ~/golang/projects/ownmkdir ~/golang/projects/own/binmkdir ~/golang/projects/own/pkgmkdir ~/golang/projects/own/src3、在 $HOME/.bashrc 中添加如下內容並儲存(不用重啟)export GOROOT=$HOME/golang/goexport GOPATH=$HOME/golang/projects/3rdparty:$HOME/golang/projects/ownexport GOARCH=amd64export GOOS=linuxexport GOBIN=$GOROOT/binexport PATH=$PATH:$GOROOT/bin4、安裝 gocode,在終端輸入以下命令:go get -u github.com/nsf/gocodego install github.com/nsf/gocode5、下載並安裝 Sublime Text 3,下載地址:http://www.sublimetext.com/3點擊相應的“系統類別型”連結,可以下載安裝包。6、給 Sublime Text 3 安裝 Package Control:開啟 Sublime Text 3,按下 Ctrl + `(反引號,Tab 鍵上面),輸入如下內容並斷行符號:import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())安裝完畢後重啟 Sublime Text 3。7、安裝 GoSublime 和 SidebarEnhancements:開啟 Sublime Text 3,按下 Ctrl + Shift + P,在彈出的視窗中輸入 pcip 斷行符號,此時 Sublime Text 3 會通過網路搜尋可安裝的包資訊,稍等一會,會彈出包列表,輸入 GoSublime 斷行符號,等待 GoSublime 安裝完畢。安裝完畢後,可能會提示 GOROOT GOPATH 未設定,不管它,等會再設定(這個和系統內容變數中設定的 GOPATH GOROOT 不相干)。再次按下 Ctrl + Shift + P,在彈出的視窗中輸入 pcip 斷行符號,稍等一會,會彈出包列表,輸入 SidebarEnhancements 斷行符號,等待 SidebarEnhancements 安裝完畢。8、設定 GOPATH 和 GOROOT:開啟 Sublime Text 3,菜單“Preferences -> Package Settings -> GoSublime -> Settings-Default”,開啟 GoSublime 的設定檔,修改 env 的設定資訊:{ ... // 省略 "env": { "GOROOT": "~/Golang/go", "GOPATH": "~/Golang/Projects/3rdparty:~/Golang/Projects/own" }, ... // 省略}設定完畢要重啟 Sublime Text 3。9、全部設定完畢:開啟 Sublime Text 3,編寫一段 Golang 代碼,並儲存為 test.go。
--------------------------------------------------package mainimport ( "fmt")func main() { fmt.Println("Hello World !")}--------------------------------------------------
按下 Ctrl + B,開啟編譯視窗,輸入 go run ./test.go 運行當前檔案。
轉貼:http://www.cnblogs.com/golove/p/3810931.html