Golang Environment Construction

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Operating system Ubuntu 12.04 64-bit

1. Configuring the compilation Environment

The Go tool chain is written in C and needs to be installed with the following development tools

$ sudo apt-get install bison gcc libc6-dev ed gawk make

2. Installing the Mercurial tool

Mercurial is a lightweight distributed version control system, written in Python.

First install Python

$ sudo apt-get install python2.7

$ sudo apt-get install Python-all-dev

$ sudo apt-get install Python-setuptools

Installing mercurial

$ sudo easy_install-u Mercurial

Test the following after the installation is complete

$ hg-v

3. Get Go Source

$ HG Clone-u Release Https://go.googlecode.com/hg/go

4. Compiling the source code

$ CD GO/SRC
$./all.bash


5. Configure environment variables after successful compilation

$ sudo gedit ~/.BASHRC


Add the following content:

#golang
Export Goroot=~/go
Export GOARCH=AMD64
Export Goos=linux
Export gobin= $GOROOT/bin
Export gotool= $GOROOT/pkg/tool/linux_amd64
Export path= $PATH: $GOBIN: $GOTOOL

Where Pkg/tool/linux_amd64 is the location of the 6g 6l tool.

6. Testing

The Test.go file code is as follows

Package Main

Import "FMT"

Func Main () {
Fmt. Printf ("Hello, world\n")
}



Compiling, linking, executing

$6g Test.go
$ ls
Test.6 Test.go
$6l test.6
$ ls
6.out test.6 Test.go
$./6.out
Hello, world

Or just run go run test.go

The Ps:go compiler supports three instruction sets, and the code quality generated by different architectures differs:

AMD64 (a.k.a.x86-64) 6g 6l 6c 6a The most mature implementations, the compiler optimizes at the register level, producing high-quality target code.

386 (a.k.a.x86 or x86-32) 8g 8l 8c 8a AMD64 full porting

Arm (a.k.a.arm) 5g 5l 5c 5a

Reference: Http://wiki.ubuntu.org.cn/Golang

Http://code.google.com/p/golang-china/wiki/install


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.