Use Sublime Text 2 to build the go development environment under Ubuntu

Source: Internet
Author: User
Tags install go gocode
This is a creation in Article, where the information may have evolved or changed.

Hello everyone, these days to Golang under the environment, today to share with you the next experience.

Go is a open source programming environment that makes it easy-to-build simple, reliable, and efficient software. Excerpt from the introduction of golang.org home page.

Go is a compiled, hair-style, and garbage-collected programming language developed by Google.
Robert Greysmore (Robert griesemer), Rob Paik (Rob Pike) and Ken Thompson began designing the Go language in September 2007, and the Go language was developed based on the Inferno operating system.  The go language was officially launched in November 2009 and implemented on Linux and Mac OS x platforms. Excerpt from Wikipedia

The following is the go mascot, very cute.

This is the Hello World code for Go:

Package Main
Import "FMT"

Func Main () {
Fmt. Println ("Hello, World")
}

At first glance, does it feel like C, and next brings you to the installation of the Go development environment.

The first is to install Go, here is a very detailed installation instructions, Http://code.google.com/p/golang-china/wiki/Install from Golang-china this side everybody in order to do, Do not repeat the building of the car. Here due to different versions, different systems, there can be some differences, first of all, my operating system for Ubuntu 64, go source directory for $HOME/go, after successful installation, did not appear the following line:

You need to Add/home/you/go/bin to your $PATH. * * *
The compiler is6g.

Next is the. BASHRC configuration as follows:

Export goroot= $HOME/go
Export GOARCH=AMD64
Export Goos=linux
Export gobin= $GOROOT/bin
Export path= $PATH: $GOROOT/bin

Compile Helloworld.go as follows:

Go Build Helloworld.go

Run as follows:

./helloworld

Note that my helloworld.go file is in the $HOME directory.

The above is the installation process, I encountered different from the above article.

After installing the go, we can build the development environment , here I use Sublime Text 2 + gosublime + Gocode. For those who do not know Sublime text 2, you can read this article, Sublime Text 2 Getting Started and tips

1. Download Sublime Text 2, address as follows: http://www.sublimetext.com/

2. After the decompression, double-click Sublime_text, you can use sublime text 2.

3. Install the package Control, after opening Sublime Text 2, press the shortcut key Ctrl + ', open the Command window line, ' This button on the TAB key above, I just started not found, hehe. Enter the following and return to:

Import Urllib2,os; Pf= ' Package control.sublime-package '; Ipp=sublime.installed_packages_path (); Os.makedirs (IPP) if not os.path.exists (IPP) else None; Urllib2.install_opener (Urllib2.build_opener (urllib2. Proxyhandler ())); Open (Os.path.join (IPP,PF), ' WB '). Write (Urllib2.urlopen (' http://sublime.wbond.net/' +pf.replace (', '%20′ '). Read () ); print ' Restart Sublime Text to finish installation '

4. After restarting Sublime Text 2, it is possible to find a menu item in the Preferences menus under the package Control.

5. Install Gocode, open Terminal, enter the following (need to install Git tool, sudo apt-get install git):

Go get Github.com/nsf/gocode

Go Install Github.com/nsf/gocode

After the installation is complete, we can find an extra Gocode file in the Go/bin directory.

6. Install the Gosublime plugin:

After opening Sublime Text 2, locate the package control under the Preferences menu, click Open, a package control interface will appear, enter the Install package, wait a while, and another interface will appear. At this time, enter Gosublime, click the item that appears, you can install gosublime successfully.

7. Modify the Gosublime configuration: Under the Preferences menu, locate the package Settings, find the Gosublime, and then find Settings–default. Re-open the file, add the following configuration, and save:

Well, so far, the development environment has been built.

Originally wanted to cut a few pictures up, helpless Ubuntu, too weak.

Helloworld.go compile, and run :

Open Sublime Text 2, create a new helloworld.go, and write the following code:

Pressing the shortcut key below the Ctrl + B interface will appear as follows:

Enter Go build helloworld.go

Run, also press the shortcut key Ctrl + B below the interface will appear below, and delete go, enter./helloworld.

Enter, you can see the result:

Well, by now, the development environment has been set up, I hope you will also learn the language of go.

Finally, attached to the "Learning go Language" 0.4 Chinese version, personally think no more than this ebook, more suitable for the start go, thank you for your support.

2012-11-16 Supplement:

Add Gosublime configuration to prevent compiling the Go program times error with the external package as follows:

"PATH": "$HOME/go/bin: $HOME/workplace/rhino/bin: $PATH",

"Gopath": "$HOME/workplace/rhino: $PATH"

2013-07-19 Supplement:

Do not set the GOBIN environment variable, otherwise the compilation result will be installed first to the directory specified by the variable.

Do not put the go file directly in the SRC directory, should be placed under the Src/example similar package, so go install, in order to correctly generate the executable file in the bin directory.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.