The Go language, developed by Google scientists and open source, is known as the "C language of the 21st century", and its main goal is to combine the security and efficiency of static language with the easy development of dynamic language to achieve a perfect balance, thus making programming more enjoyable rather than painful in difficult choices.
The project team decided to develop a front-end flood-fighting server in the go language, with a recent project dealing with the instant high concurrency request, taking into account the native support concurrency feature of the Go language and the development of multiple projects in the go language after the new year. 工欲善其事, its prerequisite, below the Linux system under the development of the go environment to build.
There is a lot of information on the go environment, which is installed from the installation mercurial
, then download the Go language source. But because of the well-known reasons, there is no stable access to Google's servers in mainland China, so the above method is not feasible in many cases, unless a proxy is used. Here's a very simple and very effective way to build a go development environment.
注意
: To install the Go development environment under Linux, please use the root user .
# # #下载Go文件压缩包
To Golang Chinese community to download the source of the Go language, the Linux command line can execute the following command:
1 |
wget http://www.golangtc.com/static/go/go1.8.3.linux-amd64.tar.gz |
Unzip the file after downloading:
1 |
TAR-ZXVF go1.8.3.linux-amd64.tar.gz |
To get a go
directory, execute the following command to move to the /usr/local/
directory:
# # #Go配置环境变量
To open a file using the Vim editor /etc/profile
:
At the bottom, add the following to configure the GO locale variable:
12345 |
#set Go Environment goroot=/usr/local/Go gobin= $GOROOT/bin path= $PATH: $GOBIN/ export Goroot GOBIN PATH |
The environment variable configuration in the Code>/etc/profile file ensures that the environment variable is available to every user on the machine. Execute the following command to make the environment variable effective:
Verify that the environment variable is in effect and if the console outputs the path configured above, the configuration succeeds:
To switch to the user who deploys the Go service, you can, of course, continue to be the root user, configuring GOPATH
environment variables:
Edit the following in the bottom section:
Then run the following command to make the environment variable effective:
Create a file in the /data/go directory main.go
and write the following:
1234567 |
Package Main Import "FMT" func main() { fmt. Println ("Hello, World! ")} |
Run after Save:
12 |
Go Run/data/go/main.gohello, the world! |
The successful printing of the message means that the installation is successful!!
Linux system Go development environment building