MAC OS x System build Google Go language development tool Sublime Text 2 environment configuration

Source: Internet
Author: User
Tags sublime text

First, install the Golang SDK

At the official website http://golang.org/directly download installation package can be installed. Download the latest installation package in the PKG format, double-click directly to run, follow the prompts to complete the installation.

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

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

  II. environment variable configuration (gopath)

Gopath is used to tell Golang commands 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 of source files (SRC), related packages (pkg), and execution files (bin).

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

After you've built your workspace, you can start configuring Gopath (the profile is ~/.bash_profile).

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

After the save, source ~/.bash_profile, it completes the configuration of the Gopath, you can go under the terminal to see the configuration after the effect.

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

  Iii. development tool Configuration (Sublime Text 2)

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

After downloading, the installation can be done directly.

Sublime Text 2 can be used free of charge, just save the number of times to reach a certain number will be prompted to buy, click Cancel can continue to use, and the official registered version without any difference.

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

1. Install 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 ' Please restart Sublime Text to finish installation '

Before installation:

After restarting Sublime Text 2:

This means that the package control installation was successful.

  2. Install Gosublime plugin:

Command + Shift + P opens Package control and then enters Pcip (Package control:install Package), as shown in the following illustration:

In the subsequent interface input gosublime, enter, you can install the gosbulime. (The source code of this plugin is in https://github.com/DisposaBoy/GoSublime)

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

Here, the Golang development environment of Sublime Text 2 is completed.

  Four, start Golang

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

Sublime Text 2 has automatic completion of code for Golang:

For the prepared file, use the shortcut command + B to open the sublime Text 2 terminal and enter the Go Build (name) to compile it:

After the compilation succeeds, 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:

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.