ubuntu10.04 Under Install configure Go language environment

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

On the Go language

Introduction: Always want to study Google cattle to get out of the go language, and finally in the "Go language father Talk go: Boulevard to Jane" This article, Ann can't resist curiosity, to experience what go language is!

1. Installation Environment ubuntu10.04

2. Install the Go version Control tool----This is to download the Go language installation source

~$:sudo apt-get Install mercurial

~$ HG
Distributed Software Configuration management tool-Mercury

Basic command:

Add add the specified files on the next commit
Annotate show changeset information by line for each file
Clone make a copy of existing repository
Commit commit the specified files or all outstanding changes
diff diff repository (or selected files)
Export dump the header and diffs for one or more changesets
Forget forget the specified files on the next commit
Init create a new repository in the given directory
Log Show revision history of entire repository or files
Merge Merge working directory with another revision
Pull pulling changes from the specified source
Push push changes to the specified destination
Remove remove the specified files on the next commit
Serve export the repository via HTTP
Status show changed files in the working directory
Summary Summarize working directory State
Update Update working directory

Use "Hg help" to get a list of all commands, or "hg-v" for more information

Yes, a version management tool, found almost like git

3. Setting up the Go installation compilation environment

~$:vim. BASHRC

At the end of the file, add the following:

goroot= "$HOME/go" # $HOME =/home/username
Export Goroot
goos=linux# system
Export GOOS
goarch=386# Platform
Export Goarch
gobin= "$HOME/bin"
Export GOBIN
Path= $PATH: $GOBIN # Ensure proper compilation and installation
Wq Save Launch
4. After configuring the environment, use the version Control tool installed in step 2nd to download go source

~$:HG clone-r Release https://go.googlecode.com/hg/$GOROOT

After completion in the $home directory can see the Go directory, which contains the download of the Go language source

5. Compiling the downloaded Go source

~ $CD $GOROOT/SRC
~$./all.bash

After the execution is completed to the $gobin directory

~ $CD $GOBIN
~ $ls
Go Godoc gofmt

Discover that the relevant executable file for GO is already installed

You can test the GO command

~$ Go
Go is a tool for managing go source code.

Usage:

Go command [arguments]

The commands are:

Build compile packages and dependencies
Clean Remove object files
Doc run Godoc on package sources
ENV Print Go Environment information
Fix run Go tool fix on packages
FMT run GOFMT on package sources
Get download and install packages and dependencies
Install compile and install packages and dependencies
List List Packages
Run compile and run Go program
Test test Packages
Tool run specified Go tool
Version Print Go version
Vet Run Go tool vet on packages

Use the "Go help [command]" For more information about a command.

Additional Help Topics:
Gopath gopath environment variable
Packages description of the package lists
Remote Remote import path syntax
Testflag Description of testing flags
TestFunc Description of testing functions
Use ' Go help [topic] ' For more information on that topic.

6. Write a simple example to verify that the Go compiler link execution process

Create the Hello.go file in any directory, as follows:

Package Main
Import "FMT"
Func Main () {
Fmt. Printf ("Hello, world;\n");
}

Then use 8g hello.go to compile, use 8l hello.8 to link, in execution./8.out

Found here the 8g (386 platform) and 8l (386 platform) are not recognized, no this command

To the Goroot directory, look for 8g, 8l

~/go$ find./-name "8g"
./src/cmd/8g
./.hg/store/data/src/cmd/8g
./pkg/tool/linux_386/8g

Found under./pkg/tool/linux_386/have the relevant command, apart the directory so

Executable command file copy to $gobin directory

~/go$ CP./pkg/tool/linux_386/* $GOBIND

I don't know why I didn't make a copy when I was doing/all.bash.

I'll do that when I go to design.

OK, then do it again: Compile, link, execute to get the results.

7. Finally verify the installation of the go language is completely correct

Execute the run script in the directory under the $goroot directory that has a test

~ $CD $GOROOT/test
~/go/test$./run
0 known Bugs; 0 Unexpected bugs

ok! no bug, no exception;


Add:

The go compiler can support three sets of instructions. There are some differences in the quality of code generated by different architectures:
AMD64 (a.k.a. x86-64); 6g,6l,6c,6a
The most mature implementations, compiler optimizations at the register level, can generate high-quality target code (sometimes gccgo may be better).
386 (a.k.a. x86 or X86-32); 8g,8l,8c,8a
Complete porting of the AMD64 platform.
Arm (a.k.a. arm); 5g,5l,5c,5a

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.