This is a creation in Article, where the information may have evolved or changed.
I've been focusing on the go language since 2009, and now the go language has grown to version 1.2, and more and more people are paying attention to the language. The purpose of the Go language design is to solve the problem of fast execution times but not ideal for compiling several times (such as C + +), fast compilation speed but inefficient execution (. NET, Java), or the development of dynamic languages that are less difficult but perform at a general speed. So, the Go language features: Fast compilation, efficient execution, easy to develop.
Well, skip the craps of the boxes, let's start with the Go language environment first, because the recent preference for Ubuntu, in addition as an open source language, on Linux from the source code to build the environment more interesting.
Of course, if you need to build the environment quickly, you can also refer directly to the official documentation: Http://golang.org/doc/install.html. Given that the official documentation is very detailed, I will not be one by one.
1. Set the GO environment variable
Open terminal, enter command:
Export goroot=$HOME/go
Export path= $GOROOT/bin: $PATH
Of course, you need to set the project directory
Gopath= $HOME/applications/go
2. Installing the C tool
Since Go's toolchain is written in C, the preamble installs the relevant C tools before installing go. Execute the command:
sudo apt-get install bison ed gawk gcc Libc6-dev make
3. Installing mercurial
Since the go source code is managed through mercurial, it is necessary to install mercurial to achieve the go source, one time to execute the command:
sudo apt-get install python-setuptoolssudo apt-get install pythone-devsudo apt-get install build- Essentialsudo apt-get install mercurial
4. Get Go Source code
HG Clone-r release https://go.googlecode.com/hg/$GOROOT
5. Build Go
Execute a command in the terminal to build the go
CD $GOROOT/SRC
./all.bash
The compilation will be automatically tested, but will be linked google.com when testing net/http, a little bit unstable in the domestic environment (the first compilation successfully hangs ...), so the suggestion is to add an environment variable
Export Disable_net_tests=1
To skip the net test.
6. Test the installation
After the installation is complete, create a new document to test the environment for success:
Example Helloworld.go
1 Package Main2 3 Import (4 "FMT"5 "Runtime"6 )7 8 Func Main () {9Fmt. Println ("Hellow world!", runtime. Version ())Ten}
To execute go run helloworld.go, you should print out:
Hellow world! Go1. 2