先下載Go的安裝包修械, Link as : https://golang.org/dl/
安裝 Go到你指定目錄疑苫, 我用的是D:\Go
設(shè)置系統(tǒng)的環(huán)境變量, "我的電腦"->鼠標(biāo)右鍵->"屬性" -> "Advanced System Setting" -> System Properties -> Environment variable ->"Path", 編輯并添加"D:\Go\bin"到path的結(jié)尾.
打開eclipse,我的版本是:Neon.3 Release (4.6.3)
-
Eclipse->Help->Install New Software…->點擊Add 按鈕梳毙,
在”Name“內(nèi)輸入:Goclipse Site在”Location“內(nèi)輸入:http://goclipse.github.io/releases/
image
-
點擊"OK"按鈕
image 選中“GoCclipse”->“Next”button.
等 ..............下載完成后, 重啟eclipse.
-
設(shè)置Go的工作環(huán)境, Eclipse->Window->Preferences 找到"Go"的設(shè)置.
--> Directory: {Go的安裝路徑}-->Eclipse GPPATH: 設(shè)置工作路徑.
-->Apply
![image](http://upload-images.jianshu.io/upload_images/10296731-f33a7b4a8897b6d5?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
- 選擇Go->Tools, 填上gocode, guru, godef對應(yīng)的exe文件.
![image](http://upload-images.jianshu.io/upload_images/10296731-fea86c859ab4d4b9?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
如果你安裝的go沒有自帶這幾個程序, 你需要手動添加, 添加的方法如下:
* gocode是go語言自動補全守護程序, 從https://github.com/nsf/gocode下載源碼,如果你有g(shù)it在地, 可以用git clone, 如果沒有, 也可以通過頁面上的"Clone or download" button去下載一個zip包, 名字為gocode-master.zip,解壓縮這個包.如: d:\gocode-master, 從windlow控制臺進去, cmd, 在這個目錄下執(zhí)行"go build" 命令. 如下圖
![image](http://upload-images.jianshu.io/upload_images/10296731-658eba88c3e47279?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
這里會生成一個gocode-master.exe文件, 你可以改名為gocode.exe, 然后將空上gocode.exe文件copy到Go的安裝目錄bin下, 如d:\Go\bin.
* guru, 它是Go的代碼導(dǎo)航程序, 首先要下載源碼從`https://github.com/golang/tools`,與gocode一樣, 如果沒有g(shù)it, 直接下tools-master.zip包. 在Go的安裝目錄建文件夾, 如d:\Go\src\golang.org\x\tools\cmd\guru, 將tools-master.zip的包內(nèi)容解壓到guru下, 通過控制臺進入D:\Go\src, 執(zhí)行編譯命令: `go install golang.org/x/tools/cmd/guru`.這個命令之后, 如果成功, 你會在D:\Go\bin下見到guru.exe文件.
* godef:是Go的代碼跳轉(zhuǎn)程序. 首先下載源碼從https://github.com/rogpeppe/godef,文件名為godef-master.zip.需要在D:\Go\src目錄下創(chuàng)建文件夾, D:\Go\src\github.com\rogpeppe\godef 將godef-master.zip里的文件內(nèi)容解壓到godef文件下, 注意不帶"godef-master"這一層文件夾, 前面的guru也一樣. 然后在D:\Go\src\github.com\rogpeppe\godef下執(zhí)行"go install" 命令.它會成生godef.exe在D:\Go\bin下.
-
下載一個gdb64.exe用于debug. https://sourceforge.net/projects/liteide/files/X31/liteidex31.windows-qt4.zip/download?use_mirror=excellmedia&r=&use_mirror=excellmedia, 下載一個liteide最新版本. 解壓之后 從bin時copy一個對應(yīng)你操作系統(tǒng)的exe, 我的是win64, 于是copy gdb64.exe 到D:\Go\bin下.
配置gdb64.exe到eclipse里.
->Eclipse->File ->New "Go Project"->new a go file, Hello.go.
->鼠標(biāo)右鍵Debug Configuration, 配置gdb64.exe,如下:
image 可以通過一個小測試verify一下環(huán)境是否working: 如:
<pre class="plain">package main
import "fmt"
func init(){
fmt.Println("run init firstly, right?")
}
func main(){
fmt.Println("hello yqqq, how are you?");
}</pre>
運行結(jié)果為:
<pre class="plain">run init firstly, right?
hello yqqq, how are you?</pre>