How to build the Go language development environment in Mac _golang

Source: Internet
Author: User
Tags error handling garbage collection sublime text

Objective

The go language, which is the language of Google's internal push, serves as a new, statically typed development language with many exciting new features compared to the current development language. Optimized for multiprocessor system applications, the go language is perfectly comparable to C, C + +, and is more secure, concise, and supports parallel processes.

The following are the main features of the Go language:

1. Automatic garbage collection

2. Richer built-in types

3, the function of multiple back-return value

4. Error handling

5. Anonymous functions and closures

6. Types and Interfaces

7. Concurrent Programming

8, Reflection

9. Language interactivity

The MAC development environment constructs

The above basic is nonsense, build the development environment as soon as possible to open programming journey is kingly, the author uses is the MAC system, therefore introduced under the MAC under the Golang environment to build.

1, install the Golang SDK

Google website by the wall to download the address below: http://www.golangtc.com/download, download the latest installation package, and then double-click the installation can be.
After the installation is complete, open the terminal and enter the following message for the go, or go version (view installation), which means the installation was successful:

lcore:~ lcore$ Go version go1.4.1 darwin/amd64 lcore:~ lcore$

2. Configure Environment variables

After installing the SDK, the next step is to configure the environment variable, open the terminal input cd ~ into the user's home directory, and then enter the ls -all command to see if there is a .bash_profile file, which exists both to use to vim .bash_profile open and edit the file. If it doesn't exist, create it yourself. According to their own actual situation, the content is as follows:

Export Gopath=/users/lcore/dev/code/go
export gobin= $GOPATH/bin
export path= $PATH: $GOBIN

Gopath: The root directory of daily development.

Gobin: is the bin directory under Gopath.

And you need to add the Gobin directory to the path, the resulting executable file runs directly.

Quit Vim, use source ~/.bash_profile to complete the configuration of the Golang environment variables, you can enter the terminal to go env view the configuration after the effect:

lcore:~ lcore$ Go env goarch= "AMD64" gobin= "/users/lcore/dev/code/go/bin" gochar= "6" goexe= "" Gohostarch= "AMD64" Gohostos= "Darwin" goos= "Darwin" Gopath= "/users/lcore/dev/code/go" gorace= "" goroot= "/usr/local/go" gotooldir= "/usr/ Local/go/pkg/tool/darwin_amd64 "cc=" clang "gogccflags="-fpic-m64-pthread-fno-caret-diagnostics-qunused-arguments -fmessage-length=0-fno-common "cxx=" clang++ "cgo_enabled=" 1 "

3, development tool configuration (sublime text)

Here the author chooses is sublime text installs the gosublime plug-in to carry on the development (Golang syntax highlights the hint), installs the way here does not mention.

Hello Go

After configuring the development environment, simply go to the development of the go language. Under your gopath src directory, create a new folder (named after the project name) and sublime open the folder in, and the new main.go file will be encoded.

Package main

import ("FMT") func main () {FMT. Println ("Hello Go"); }

After the code is written, use the command+b open sublime text terminal, go build xx compile it with the name of the project, and compile the resulting information as follows:

[' Go build Hellogo ' | done:420.495985ms]

After the compilation succeeds, execute the shell command, and execute the file you just compiled to see the results of the ./hellogo run:

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

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

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

Summarize

So far, we have installed the basic environment for the development of Golang program, you can enjoy the Golang of the wonderful place! I hope this article for everyone to go language development environment can help, if you have questions can be exchanged message.

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.