Golang (Go language) MAC OS x Environment environment variable Configuration development tool configuration Sublime Text 2 "Go"

Source: Internet
Author: User
Tags sublime text

First, install the Golang SDK

On the official website http://golang.org/Download the installation package directly. Download the most recent installation package in PKG format and run it directly by double-clicking and follow the instructions to complete the installation.

After the installation is complete, open the terminal, enter go, detect if the Golang SDK is successfully installed, as shown below, indicates the installation is successful:

  

You can also enter Go version to view the version of Golang you have installed.

Second, environment variable configuration (gopath)

Gopath is used to tell the Golang command and other related tools where to find the Go package directory on your system.

Gopath is a list of paths, similar to the settings for path:

gopath=/home/user/go:/home/user/workspace_go:***

The path to each list item is actually a workspace, and each workspace should contain three directories for the source file (SRC), the related package (pkg), and the execution file (bin).

Http://golang.org/doc/code.html

Once you've built your workspace, you're ready to configure Gopath (the configuration file is ~/.bash_profile).

Export Gopath=/users/heinoc/go:/users/heinoc/documents/workspace/workspace_go

After saving, source ~/.bash_profile, completed the configuration of the Gopath, you can look at the terminal go env to see the effect of the configuration.

(Note: I will generally give gopath at least two directories, when you need to download the Open source package (Go get * * *), the open source package by default will find the first directory, will be unified down to the first directory of the Pkg folder, my native development projects are all saved in the Gopath directory behind, Just for convenience Management Pack, how to configure, see your personal preference)

Iii. development tool Configuration (Sublime Text 2) 

Sublime Text 2:HTTP://WWW.SUBLIMETEXT.COM/2

After downloading, you can install directly.

Sublime Text 2 can be used for free, just after a certain number of save times will be prompted whether to buy, click Cancel can continue to use, and the official registration version no difference.

Introduction to Sublime Text 2: http://lucifr.com/2011/08/31/sublime-text-2-tricks-and-tips/

  1. Install the package Control

CTRL + ' Open the command line and execute the following code:

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 '

Before installation:

  

After restarting Sublime Text 2:

  

This means that the package control installation was successful.

2. Install the Gosublime plugin:

Command + Shift + P Open the package Control and enter PCIP (the package control:install the abbreviation) as shown:

  

Enter Gosublime in the following interface, and you can install Gosbulime. (The source code for this plugin is https://github.com/DisposaBoy/GoSublime)

  

After the installation is complete, you can see the following in the menu:

  

Here, the Sublime Text 2 Golang development environment is built.

Iv. beginning of Golang

In your Gopath workspace, create a new folder under the SRC directory, name the project name, and then drag the folder onto sublime Text 2 to open the item in sublime Text 2, then create a new file inside it, save as "***.go", Then you can start coding:

Sublime Text 2 has a code auto-completion function for Golang:

  

For a well-written file, use the shortcut key command + B to open the terminal of Sublime Text 2, and enter the Go Build (name) to compile it:

  

After compiling successfully, execute the shell command and execute the newly compiled file./gotest can see the results of the program running:

  

The results of the operation are as follows:

  

=======================================================================

Resources:

Gosublime shortcut keys can be see the following article:

Https://github.com/DisposaBoy/GoSublime/blob/master/USAGE.md

Golang/go language/go ide/go Windows environment build/go automatic prompt compiler/gosublime
http://blog.csdn.net/love_se/article/details/7754274

Use Sublime Text 2 to build the go development environment under Ubuntu
Http://www.cnblogs.com/yourihua/archive/2012/06/04/2529333.html

Golang (Go language) MAC OS x Environment environment variable Configuration development tool configuration Sublime Text 2 "Go"

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.