Go Language Environment Installation
1.Brew Install Go
The default installation, the/usr/local/cellar/go directory is installed and the environment variable is set by itself.
2.Go env to view the current environment variables for Go
3. Configure a Gopath environment variable, which is the working directory.
According to the Convention, 3 directories need to be established under Gopath:
Bin stores the compiled executable file
Pkg to store package files generated after compilation
SRC Store the source code of the project
I built Gopath on/users/xinshaofeng/study/gowork.
VI ~/.bash_profile
Join: Export Gopath=/users/xinshaofeng/study/gowork
to take effect immediately please run: Source ~/.bash_profile
4.go env View the configured environment variables
xilanglangdeMacBook-Pro:~ xinshaofeng$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xinshaofeng/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xinshaofeng/Study/gowork"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/35/77w42bv10v3dssfhnzm0yftm0000gn/T/go-build511520829=/tmp/go-build -gno-record-gcc-switches -fno-common"
xilanglangdeMacBook-Pro:~ xinshaofeng$
Sublime Text 3 installation in the MAC environment:
1.Sublime Text 3 Download installation address http://www.pc6.com/mac/120663.html
Go language-related plugin gosublime installation
1. Install the package Control: Open Sublime Text 3, press and hold Command+shift+p (Tools->command Palette), pop up the following input window, enter the install package, And check the list in the Red box to enter.
2. Then in the pop-up input window, input gosublime, enter the Gosublime, at this time after the successful installation, restart Sublime Text 3.
3. Next you can develop the code, finally can write the Go Language program, press and hold command+b can compile your command source files.
Package main
Import "fmt"
Func main() {
/* This is my first simple program */
fmt.Println("Hello, World!")
}
4. If command+b has no effect, you need to go to the toolbar Tools->build system->new Build System and enter the following text in the newly opened text:
{
"cmd": ["go", "run", "$file_name"],
"file_regex": "^[ ]*File \"(…*?)\", line ([0-9]*)",
"working_dir": "$file_path",
"selector": "source.go"
}
5. Save, name it as Go.sublime-build. Then select Go in the Tools->build system, and this time you will be able to get the results in the command+b operation.
Go environment Build, Sublime Text 3 install Go language related plug-in gosublime