Ubuntu Configuration Go Language development environment (Sublime Text+gosublime)

Source: Internet
Author: User
Tags mercurial sublime text

This article is for the Go language version of 1.3, before the relevant article on how to configure the Go language development environment in Ubuntu, but in the past, some methods are different or unnecessary. Although the installation of Ubuntu under the configuration process, but the Windows system not only download more convenient, configuration environment part of the same, where 64-bit system of the GCC compiler can be downloaded to http://tdm-gcc.tdragon.net/.

First step: Install the Go language-related tools
Please enter the following instructions at the terminal (if it is found that the download speed is general, it is recommended to install each separately, or an installation failure will result in all the failed installation):

?
1 sudoapt-get install bison ed gawk gcclibc6-dev make

After all the installation is complete, you can proceed to the next step

Step Two: Install Mercurial (if you do not want to install, you can skip to the third step Method II)
Mercurial is a version management system, commonly known as HG, can be directly in the terminal input "HG" to check whether the software has been installed, because we need to from Google code in the Clone Go language source package, and its use of the version management system for Mercurial, so we have been The software needs to be installed before it can be installed, it is very convenient to install under Ubuntu, enter the following command in the terminal:

?
1234 sudo apt-get Install python-setuptools sudo apt-get install Python-dev sudo apt-get install build-essential sudo apt-get install mercurial

Step three: Get the Go Language source package
Method One: Please use the "CD" command to jump to the path you want to save the go language source, because the environment variable set up after a lot of trouble, of course, you can also use the "MV" command to move to any location you want, but it is recommended to put it at once. Then enter the following command at the terminal:

?
1 hg clone -r release https://go.googlecode.com/hg/go

Method Two: To http://golang.org/dl/(or wall http://www.golangtc.com/download) page, select the appropriate source package for your system, download and extract to the specified location, note the source package root directory name should be go, You need to set the environment variable in a while, go this folder should contain roughly like content:

Fourth step: Configure the Go language environment variable
The configuration of environment variables is critical in the next step of compiling the Go Language source code or later in the development process.
First, use any text editor to open the. bashrc file in your home directory, and if you're not sure where it is, enter the following instructions directly at the terminal:

?
1 nano ~/.bashrc

Then go to the text editing interface, please append to the file at the end of the approximate content:

Among them, Goroot should be the location where you store the source package, that is, you just obtained the source code extracted after the absolute path of the Go folder, for example: My path is $HOME/go
Goarch and GOOS are related to the distribution you downloaded, for example: My 32-bit Ubuntu, so goarch for 386,goos Linux
The setting of path is the most critical, first enter "${path}:" On the right side of the equal sign, and then enter the path of the Bin folder under the Goroot path in front of you, for example: My goroot path is $HOME/go, then what you need to append is $HOME/go/bin
The last Gopath is your working directory, can be modified at any time, but according to the Convention, in this directory, contains at least three folders, Bin,pkg,src,bin folder for the compilation of the generated files, pkg for the post-build package (. A end), SRC Folders are used to store various types of source files, including the source code that you get from the network, and the source code that you write, so that the go will work properly at compile time.

When the edits are complete, save to exit.
Then enter the following command at the terminal to make our settings effective:

?
1 $source.bashrc

Fifth step: Compiling Go source code
Please enter the following instructions in the terminal to switch to the source folder and start compiling:

?
12 cd$GOROOT/src./all.bash

Wait a moment, after the compilation is complete, should appear roughly as information:

Then, after the terminal input command go, if you see the following information, the basic work has been completed!

Sixth step: Download Sublime Text
Plane ticket: http://www.sublimetext.com/
After the download decompression, double-click Sublime_text, you can use it, as to how to add to the Launcher, please refer to the blog: http://my.oschina.net/Obahua/blog/110612

Seventh Step: Install Gosublime
First, we need to install the Sublime Text of the package Control function, after opening the software, press the shortcut key Ctrl + ', (' This symbol for the English half-width mode, press the TAB key above the number key 1 left button), a command window will open, Copy and enter the following, and the last return:

?
1 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‘

If you use SUblime Text 3, refer to Http://wbond.net/sublime_packages/package_control/installation#ST3 to install the package control, Altogether 4 commands, very simple.

When the installation is complete, you will be prompted to restart the software, and then you will see that the menu item in the Preferences menu appears under the package Control, as shown below:

Next, we will install the Gosublime plug-in, press and hold ctrl+shift+p will pop up a session box, enter "Install" in it, after the approximate as shown:

Next press ENTER, a dialog box for the installation package appears, roughly as shown:

Enter "Gosublime", select and enter, then "Go Build", select and enter (optional).
At this point, configuration Gosublime is complete.

Eighth Step: Hello world!
Enter the following command at the terminal, create a hello.go file under your $GOPATH/src folder, and enter the text editing interface

?
1 nano $GOPATH/src/hello.go

In the text editor, enter the following:

Save and exit, and then enter the following command at the terminal:

?
1 go run $GOPATH/src/hello.go

At this point, you should see roughly as the result:

Nineth Step: Non-standard library code input hint
The latest version of Gosublime requires you to set your Gopath variable into its configuration file, otherwise it may not be possible to support code entry hints for nonstandard library packages, direct, open settings-default, copy all content, and paste into settings-user (so The practice is to ensure that your changes are not reset by the plugin update, the plugin is updated very frequently.

Next, enter your Gopath variable in the Env field and restart the settings to take effect.

Congratulations, Success! Start enjoying your fun Go language tour ~~~~~let's go!!!!!!!

Ubuntu Configuration Go Language development environment (Sublime Text+gosublime)

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.