MAC OS System Installation Golang tutorial _golang

Source: Internet
Author: User
Tags sublime text golang tutorial

Download Golang installation package

Download Address:

Http://www.golangtc.com/download
Https://code.google.com/p/go/downloads/list
Go1.4.darwin-amd64-osx10.8.pkg go1.4 Mac OS X (x86 64-bit) PKG Installer

Setting environment variables

Configure Goroot and Gopath:

Copy Code code as follows:

To create a Go folder under the directory: mkdir ~/go

The following items are placed in the. BASH_RC (or maybe. bash_profile or. ZSHRC)
Export Goroot=/usr/local/go
Export Gopath= $HOME/go
Export path= $PATH: $GOROOT/bin

Download Pkg under Mac Double-click to install, super simple, default installation path:/usr/local/go

Copy Code code as follows:

SOURCE ~/.bash_profile

Now that the Golang installation is complete, let's experience the following:

Copy Code code as follows:

Go env
Go version

Run Result:
Copy Code code as follows:

Liuxinmingdemacbook-pro:gotest liuxinming$ Go env
Goarch= "AMD64"
Gobin= ""
Gochar= "6"
Goexe= ""
Gohostarch= "AMD64"
Gohostos= "Darwin"
Goos= "Darwin"
Gopath= "/users/liuxinming/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"
=========== Gorgeous split Line ===============
Liuxinmingdemacbook-pro:gotest liuxinming$ Go version
Go version go1.4 darwin/amd64
Liuxinmingdemacbook-pro:gotest liuxinming$

Development tool Configuration (Sublime Text 2)

Sublime Text 2 Download Address: HTTP://WWW.SUBLIMETEXT.COM/2

After downloading, the installation can be done directly.

Sublime Text 2 can be used free of charge, just save the number of times to reach a certain number will be prompted to buy, click Cancel can continue to use, and the official registered version without any difference.

Start the Golang Journey

Command + Shift + P to open package control and enter go, carriage return (this will cause code hints)

Create a new Hello.go

Copy Code code as follows:

Package Main

Import "FMT"

Func Main () {
Fmt. Printf ("Hello, world\n")
}

For the prepared file, use the shortcut command + B to open the terminal of Sublime Text 2, and enter the Go Build (name) to compile it: "Note: I test, the direct shortcut is automatically compiled, do not need any input"

The problem is, the default installed sublime does not have a go build, so you need to create one yourself.

Add the Go language build for sublime Text2

Tools-> Build System-> New build System

Enter the following code:

Copy Code code as follows:

{
"cmd": ["/usr/local/go/bin/go", "Run", "$file"],
"File_regex": "^ (... *?):( [0-9]*]:? ([0-9]*) ",
"Working_dir": "${file_path}",
"Selector": "Source.go"
}

Then select the build file: Go

Then COMMAND + B will have the output.

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.