Ubuntu下安裝Go語言開發環境及編輯器的相關配置_Golang

來源:互聯網
上載者:User

安裝

Windows下是直接的安裝包,這裡我們略過,來看一下Ubuntu下安裝Go:

sudo add-apt-repository ppa:gophers/gosudo apt-get updatesudo apt-get install golang-stable

sudo apt-get install golang

或者直接下載go語言安裝包

環境配置:

vi /etc/profile

加入

export GOROOT=/usr/lib/goexport GOARCH=386export GOOS=linuxexport GOPATH=/home/administrator/workspace/goexport GOBIN=$GOPATH/binexport PATH=$GOPATH/bin:$PATHsource /etc/profile

在建立GOPATH下建立三個目錄

mkdir src pkg bin
  • src 存放源碼
  • pkg 存放編譯產生的檔案
  • bin 存放產生的可執行檔

建立第一個go應用

cd $GOPATH/srcmkdir test1cd test1vi t1.go

複製代碼 代碼如下:

package main 
 
import "fmt" 
 
func main() { 
    fmt.Println("Hello world, I'm learning Golang") 


main.main()是go應用的入口

編譯方式
1、進入對應的應用程式套件目錄,然後執行go install,就可以安裝了
2、在任意的目錄執行如下代碼go install test
3、進入對應的應用程式套件目錄,然後執行go build,就會在目前的目錄產生可執行檔

 

配置VIM支援GO語言文法高亮
cp -r $GOROOT/misc/vim/* ~/.vim/ 註:$GOROOT是go的安裝目錄
vi ~/.vimrc 加入

filetype plugin indent onsyntax on

安裝Gocode

go get -u github.com/nsf/gocode

gocode預設安裝到$GOBIN下面。

配置Gocode

~ cd $GOPATH/src/github.com/nsf/gocode/vim~ ./update.bash~ gocode set propose-builtins truepropose-builtins true

Eclipse裡編寫Go語言程式
GO語言安裝包配置很簡單,今天發現有Go語言的Eclipse外掛程式Goclipse,使得可以直接在Eclipse裡編譯調試go程式。

這裡我回到Windows下來示範,反正都差不多,同理即可,嘿嘿~
安裝這裡就略過了,安裝完成後重啟Eclipse,配置Window --> Preference --> Go

GOROOT---> C:\go  GOPATH --> C:\go  GOOS  --> windows  GOARCH --> 386  Gocode --> D:\gocode-win32\gocode.exe

   C:\go是我的go安裝位置。

   D:\gocode-win32\gocode.exe是我的gocode安裝位置

下載gocode-win32.zip,上述操作完成後,建立GO project,在src建立源檔案,a.go.接著就可以run了。

複製代碼 代碼如下:

//a.go 
package main 
 
import "fmt" 
 
func main() { 
    fmt.Printf("Hello world") 


這裡注意,Main source file需要選擇,就是go的main方法所在檔案

聯繫我們

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