This is a creation in Article, where the information may have evolved or changed.
Chapter II Go Programming Environment
Gois an open source project that usesBSD Licensing Agreement . There are currently two ways to useGolanguage. Here are the main ways to useGoSpecial-Purposegc
Series Tools (6g
,8g
, etc.). The other optional compiler is based on theGCCback end of gccgo
compiler. About thegccgo
details of the clear reference Install and use the gccgo compiler . GoIt's not yet.IDEdevelopment tools, you can write code only with Notepad,Vi,Emacsand other text editors.
2.1 Go the installation
2.1.1 Go Operating Platform
Go currently supports three types of two operating systems CPU instruction set. Linux and Mac platforms can be common, but the ARM target code cannot be run on OS X the system.
The following are the differences between compiled target code for different CPU instruction sets:
amd64
(a.k.a. x86-64
);6g
,6l,6c,6a
The most mature implementation of the present. The compiler is well tuned to produce better target code (though sometimes gccgo might do better).
386 (a.k.a. x86 or X86-32); 8g,8l,8c,8a
Although not as mature as the amd64 platform, it has been very stable.
arm
(a.k.a. ARM
);5g
,5l,5c,5a
There are still some problems that are still being perfected. Important for QEMU and android mobile environment testing.
on all platforms, there are some differences in the operating system Excuses section, and the run-Library support forGo is the same. Contains garbage memory recovery support based on the mark-and-sweep algorithm (), efficient arrays, strings, and slices, as well as independent stack support and Goroutine implementations.
Now there are enthusiasts porting it to the Windows platform, if you want to run Go on the Window platform, from http://code.google.com/p/ Download the gomingw/website to the binary release version.
2.1.2 Download Go
Go Use the Mercurial version Management system to manage the code. If you do not have Mercurial, you can download it from the Mercurial official website (http://mercurial.selenic.com/) .
Linux under platform, install with the following command:
$ sudo easy_install Mercurial
Window can be used under the platform Tortoisehg .
Make sure that GOROOT
there is no or empty directory. Then check out the code from the warehouse:
$ HG Clone-r Release Https://go.googlecode.com/hg/GOROOT
2.1.3 Setting environment variables
Go The compiler requires three required environment variables and an optional environment variable. Environment variables are .bashrc
set in or in other configuration files.
$GOROOT
Go the root directory of the installation package. It is usually put on $HOME/go
, and of course it can be another location.
$GOOS
and and$GOARCH
These two environment variables represent the target The code's operating system and cpu type. $GOOS options are linux , freebsd , darwin (Mac OS X 10.5 or 10.6) and NaCl (Chrome interface, not yet completed. $GOARCH options are amd64 (64-bit x86 , currently the most mature , 386 (32-bitx86) , and arm (32-bit arm , not yet completed . The following are possible combinations of $GOOS and $GOARCH :
$GOOS
| TD style= "WIDTH:75PT; padding:0cm, "width=", ">
$GOARCH |
|
darwin |
386 |
|
darwin |
amd64 |
|
freebsd |
386 |
|
freebsd |
amd64 |
|
linux |
386 |
|
linux |
amd64 |
|
linux |
arm |
|
Nacl |
386 |
$GOBIN
(optional) (optional)
Indicates the binary directory used to store go . If the environment variable is not set $GOBIN
, it is installed by default $HOME/bin
. If you set this variable, you need to make sure $PATH
that the variable also contains the path so that the compiler can find the correct execution file.
It should be noted that the $GOARCH
$GOOS
environment variable represents the target code runtime environment and is irrelevant to the platform currently in use. This is convenient for cross-compiling.
.bashrc
set the following environment variables in the file :
Export goroot= $HOME/go
Export GOARCH=AMD64
Export Goos=linux
Use the following command to detect the environment variable again.
$ env | grep ' ^go '
Window environment variable setting under platform
Goroot=c:/go
Goarch=386
Goos=windows
Gobin=%goroot%/bin
path=%path%;%gobin%/;
Note : Gomingw 2010-05-04 the previous version of the GOOS variable should be set to MinGW
2.1.4 Installation
Go tool chain is written in C language. So to compile the go tool, you need to now install GCC,C Standard library,Bison Analyzer, and make,awk , and Ed and other development tools. For OS X Systems, they can be used as a plug-in for Xcode . For Linux Systems, you can install them with the following command:
$ sudo apt-get install bison gcc libc6-dev ed gawk make
(if it is a different Linux version, you can install it with a similar command).
Run the following command to build Go :
$ cd $GOROOT/SRC
$./all.bash
When the compilation is complete, the following information is printed at the end.
---CD. /test
N known bugs; 0 Unexpected bugs
Windows platform, you can download the binary from the gomingw website (http://code.google.com/p/gomingw/) , extract to the specified directory, and set the environment variables to run.