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:
Now that the Golang installation is complete, let's experience the following:
Copy Code code as follows:
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.