This is a creation in Article, where the information may have evolved or changed.
<span style= "font-family:arial, Helvetica, Sans-serif; font-size:12px; Background-color:rgb (255, 255, 255); " > Learn about the go language. Before learning, first to build a go language development environment, this article mainly introduces the process of building the environment. </span>
First, install the Go language dependency package
The go language part of the function is developed in C language, so the installation go before need to install Gcc,make and other dependencies, Ubuntu under the installation command as follows:
sudo apt-get install bison ed gawk gcc Libc6-dev make
Second, get go source
After the successful installation of the Go language dependency, you need to download the Go Language source package, more methods: You can copy the source by HG, you can also go to the official website directly download the corresponding source package
1. Use HG Copy
This method requires installing Mercurial first,Mercurial is a git-like version management System, or HG (Mercury), the installation command is as follows:
sudo apt-get install python-dev sudo apt-get install build-essential sudo apt-get install mercurial
After the installation is complete, copy the code using the following command:
CD ~/ HG clone-r release Https://go.googlecode.com/hg/go
2. Direct download
Official go language download address: https://golang.org/dl/
Because of the wall, the official download address is difficult to open normally, so I will download the Ubuntu 32-bit source package on the Baidu Network disk, installation environment and my classmates can directly download this: HTTP://PAN.BAIDU.COM/S/1JGUZBHK
After download, unzip the package into the home directory.
Third, configure the GO environment variable
Before compiling the installation, you also need to set the Go language environment variable, under Ubuntu configuration method is as follows:
1. Open the. bashrc file in the home directory
Vim ~/.BASHRC
2, add the following content at the end of the file
Export gobin= $GOROOT/binexport goarch=386export goos=linuxexport path= $GOROOT/bin: $PATHexport gopath= $HOME/ Workspace/go
3. Save the settings and run the command to take effect
SOURCE ~/.BASHRC
Four, compile go source package
After the above steps are completed, the compilation script can be executed, and the command to compile the go language is as follows:
CD $GOROOT/src./all.bash
The compilation will take about 60 minutes, and when you see the following information, the installation is successful:
All TESTS PASSED---installed Go for linux/386 In/home/wuxianglong/go. Installed commands In/home/wuxianglong/go/bin.
V. Hello world!
In learning a new language, the first line of code we write is generally Hello World, and here is no exception. After performing the above steps, you can enter go at the command line and return, if the following appears, you have successfully installed:
Go is a tool for managing go source code. Usage:go command [arguments] the commands are:build compile packages and dependencies clean Remov E object Files env print Go environment information fix run Go tool fix on Packages FMT R UN gofmt on package sources get download and install packages and dependencies install compile and Insta ll packages and Dependencies list List packages run compile and run Go program test test PA Ckages tool run specified go tool version print go version vet run Go tool vet on packages use "Go help [command]" For more information about a command. Additional help Topics:c calling between Go and C filetype file types Gopath gopath Environme NT variable importpath import path Syntax packages description of package lists Testflag description of Te Sting flags TestFunc Description of TESTing functions use ' go help [topic] ' For more information on that topic.
after that, you can write a Hello World program with the following code:
Package main import "FMT" Func Main () { fmt. Printf ("Hello world!\n")}
Save the above code in the file Hello.go, and then execute it at the command line:
Go run hello.go# output: Hello world!
ok! The Go language development environment has been installed successfully!
Vim highlighting of the go language
The go language comes with a syntax highlighting file with Vim.
Copy the files in the $gosrc/misc/vim/directory to the ~/.vim/directory (if there is no new directory)
New ~/.vim/ftdetect/go.vim