Build the Go Language development environment under MAC

Source: Internet
Author: User

First, install the Golang SDK

Method One: Download the installation package SDK

installation package Download Address: https://golang.org/dl/


Download the two in the diagram

1. Double-click the. tar file, it will be automatically extracted into a folder named "Go", dragged to your user name, remember the path;

My path is:/users/haodaibao/go

2, double-click the PKG package, follow the guidelines, you can install the success.

3. Verify that the SDK installation is successful

Enter go version at the command line and get to version of Go, which means the installation was successful. The results of my verification are as follows:
Go version go1.10.3 darwin/amd64

Second, configure environment variables

1, open the terminal input CD ~ Enter the user home directory;

2. Enter the Ls-all command to see if there is a. bash_profile;

3, the existence of both using VIM. Bash_profile Open file;

4 input I into VIM editing mode;

5, enter the following code,

which

-Gopath: The root directory for daily development.

-GOBIN: Is the bin directory under Gopath.

Use method one installation, configurable

Gopath=/users/haodaibao/go

exportgobin= $GOPATH/binexport

Path= $PATH: $GOBIN

6. Click ESC and enter: Wq Save and exit the edit. You can enter Vim. Bash_profile to see if the save was successful.

7, the input source ~/.bash_profile completes the configuration to the Golang environment variable, the configuration succeeds does not have the prompt.

8. Enter go env to view the configuration results, my results are as follows:

➜~ Go env
Goarch= "AMD64"
Gobin= ""
Gocache= "/users/haodaibao/library/caches/go-build"
Goexe= ""
Gohostarch= "AMD64"
Gohostos= "Darwin"
Goos= "Darwin"
Gopath= "/users/haodaibao/go"
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/bp/sfrhrzls4q14mg9_wfj6q6j40000gn/t/go-build046962637=/tmp/go-build-gno-record-gcc-switches- Fno-common "

Third, use command line debugging


1, create the project in the SRC directory of Go, such as my go directory for/users/haodaibao/go, I create folder MSTest path for/users/haodaibao/go/src/testgo;

2, create the file Main.go, enter the following code, and save.

Package Main

Import (

"FMT"

)

Func Main () {

Fmt. Println ("Hello");

}

3. Enter go build test.go on the command line to generate the exec file;

4, click this exec file, will pop up the command line to display the following running results:

Installation is successful!

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.