Golong Language Learning--mac Building the Go Language development environment (learning excerpt)

Source: Internet
Author: User
Tags sublime text

The go language, the language of Google's internal push, is a new, static-type development language with many exciting new features compared to the current development language. Optimized for application programming for multiprocessor systems, the go language is perfectly comparable to C, C + +, and is more secure and concise, supporting parallel processes.

The following are the main features of the Go language:

1. Automatic garbage collection

2. Richer built-in type

3, function multi-return value

4. Error handling

5. Anonymous functions and closures

6. Type and interface

7. Concurrent Programming

8. Reflection

9. Language interactivity

MAC Development Environment Building

The above basic is nonsense, build the development environment as soon as possible to start the programming journey is the King, the author uses the Mac system, so the introduction of the next Mac Golang environment.

1. Install Golang SDK

Google's website is the wall as follows: Http://www.golangtc.com/download, download the latest installation package, then double-click Install.

After the installation is complete, open the terminal, enter go, or go version (view the installation version) the following information appears to indicate that the installation was successful:

Lcore: ~ Lcore$ go versiongo version go1.  4.1 darwin/amd64Lcore: ~ lcore$    
2. Configure Environment variables

After installing the SDK, the next step is to configure the environment variables, open the terminal input CD ~ Enter the user home directory, and then enter the Ls-all command to see if there are any. bash_profile

file that exists both using VIM. Bash_profile to open and edit the file. If it doesn't exist, create it yourself. According to their actual situation, the contents are as follows:

Export Gopath=/users/lcore/dev/code/goexport gobin=$GOPATH/binexport path=$PATH:$GOBIN  

Gopath: The root directory for daily development. GOBIN: Is the bin directory under Gopath.

and requires the Gobin directory to be added to the path path, the resulting executable can be run directly.

Exit vim, use source ~/.bash_profile to complete the configuration of the Golang environment variable, you can enter the effect of Go Env view configuration in the terminal:

Lcore: ~ Lcore$ go EnvGoarch="AMD64"gobin="/users/lcore/dev/code/go/bin"Gochar="6"Goexe=gohostarch= "Darwin" goos= "Darwin" gopath= "/users/lcore/dev/code/go" gorace=< Span class= "string" "" goroot= Gotooldir= "/usr/local/go/pkg/tool/darwin_amd64" cc=  "clang" gogccflags=CXX=  "clang++" cgo_enabled=     
3. Development tool Configuration (sublime text)

Here I choose is sublime text installation Gosublime plug-in development (Golang syntax highlighting hints), the installation method here is not much mention.

Hello GO

After you have configured your development environment, simply do the go language development. Under the SRC directory under your gopath, create a new folder (named after the project name), and then open the folder in Sublime, and the new Main.go file can be encoded.

Package mainImport (  "FMT") func main () {  fmt. Println ("Hello Go");}    

After the code is written, use Command+b to open the sublime text terminal, compile it with Go build xx (project name), and compile the resulting information as follows:

[' Go Build  420.495985MS]

After compiling successfully, execute the shell command and execute the file just after compiling./hellogo to see the results of the operation:

['./hellogo ' | done:10.532868ms]    Go

If you simply want to see the results of the run without producing an executable file (like the file name and project name), you can use go run xxx.go directly in the sublime text terminal:

[' Go run Main.go ' | done:314.476988ms]    Go

So far, we have installed the basic environment of developing Golang program, can enjoy the wonderful Golang!

Golong Language Learning--mac Building the Go Language development environment (learning excerpt)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.