This is a creation in Article, where the information may have evolved or changed.
[Meow Golang (2)] installation and HelloWorld
Objective
Hello, everyone! Today we are going to learn about the Go language installation and use go print out HelloWorld, this section will explain about the go language in the Liunx How to install, environment variables how to play a role, Then we run the go and print out HelloWorld, so start today's Go language tour!
Attached:
It's a kitty. Blog: w-blog.cn
Phalgo Address: Github.com/wenzhenxi/phalgo
Go Language Bible: Docs.ruanjiadeng.com/gopl-zh
1. Install the Go language
The go language supports a variety of operating systems, Windows,mac OS x,liunx,liunx support AMD64, 386, ARM architecture, windows and MAC OS X only support AMD64 and 386.
The author uses the LIUNX environment centos6.5-64-bit system here, why use Liunx also do not have to say, but in order to use the friendly hints and auto-completion function will be under the Windows development under the Liunx run, this will be explained in a later section.
First of all, we must download the Go Code package, if you go to Google, there will be a wall problem here **golang China * * For download, we can download the latest version of the 1.6.2 Go Language pack:
Http://www.golangtc.com/download
Then we download the package to the **/app/install** directory
mkrid /appmkrid /app/installcd /app/install/wget http://www.golangtc.com/static/go/1.6.2/go1.6.2.linux-amd64.tar.gz
After the decompression, move to the/usr/local/
tar -zxvf go1.6.2.linux-amd64.tar.gzmv go /usr/local/
2. Go Language environment variable configuration
We used go to use the Goroot and Gopath environment variables and they did not have the following bin executable file
Goroot: The place where you go to install the package to load the standard library
Gopath: You can set your own, work area, to store third-party code packages, as well as their source code, the default will use Goroot as the work area
Goroot-bin: where to store the go executable file
Gopath-bin: where third-party executable files are stored, you can not specify the default is Gopath/bin, but there are multiple working directories that must be specified
After describing the role of these environment variables, let's configure the environment variables:
mkdir /app/go #为做工作目录vim /etc/bashrc
Add the following statement at the end and make the environment variable effective
export GOROOT=/usr/local/goexport GOPATH=/app/goexport PATH=$GOPATH/bin:$GOROOT/bin:$PATHsource /etc/bashrc
This time directly at the command line input **go version** If you can see the following statement that the installation has been successful:
go version go1.6.2 linux/amd64
3. HelloWorld
Let's go into our set up workspace/app/go Create test.go Enter the following code:
//设置包名mian包名会自动执行main方法和C机制一样package main //你需要引入的库文件import "fmt" func main() { //使用fmt的Println方法在终端打印出语句 fmt.Println("HelloWorld") }
We then use the **go run test.go** to see the following output:
HelloWorld
4. Summary
We review the main explanation of how to install the go locale, the environment variables that need to be configured, and the respective environment variables, and then we simply set up a test.go file in our workspace and print out the HelloWorld, In the next section we will introduce how to use the IDE in the Windows environment to develop and have a good automatic prompt, has been through the code synchronization in the Liunx run our code, OK we are here today thank you for your support!
Note: The author has limited ability to say the wrong place hope that we can point out, but also hope to communicate!