Install and configure the Go Language development environment under MAC

Source: Internet
Author: User
Tags sublime text
This is a creation in Article, where the information may have evolved or changed.

1, the official website download installs the package (need FQ)

Https://storage.googleapis.com/golang/go1.7.darwin-amd64.pkg

2. Configure GO Environment variables Gopath and Gobin

(1) Open terminal, CD ~

(2) To see if there is a. bash_profile file:

Ls-all

(3) If you skip this step, there is no:

1) Create: Touch. Bash_profile

2) Editor: Open-e. Bash_profile

3) Customize Gopath and Gobin locations:

Export gopath=/users/hopkings/www/goexport GOBIN= $GOPATH/binexport PATH= $PATH: $GOBIN

(4) Compile: source. bash_profile

* View GO Environment variables: Go env

3, install sublime text of Go grammar plugin gosublime;

* Must first configure the GO environment variables Gopath and Gobin, and then install this plug-in, or plug-in will be prompted to find Gopath and gobin;

* I like to use sublime text as a development tool, so this development tool installs the go plugin. You can configure the development environment according to your development tools. The author recommends using the flexible and lightweight sublime Text.

4. Edit Test Demo:

(1) Create a new project (folder) under Gopath, and then create a new test file and save the test content:

/** * My test project:/users/hopkings/www/go/test/  or ~/www/go/test/* file path:/users/hopkings/www/go/test/main.go */package Mainimport (  "FMT") func main () {  fmt. Println ("Hello");}

(2) Run the test

You can run the GO command at the terminal, or you can run the Go command in sublime with Cmd+b.

1) Sublime Operation:

/**  * Generate compiled Files  * @output:  *          [' Go Build Main.go ' | done:1.151276122s]  */go build main.go  or go buil D ~/www/go/test/main.go  /**  * Only view running results  * @output:   *         Hello  */go run main.go  or Go run ~/ Www/go/test/main.go

2) terminal operation:

/**  * Generate compiled Files  * @output:  *          [' Go Build Main.go ' | done:1.151276122s]  */GO build ~/www/go/test/m Ain.go  /**  * View Run results only  * @output:   *         Hello  */go run ~/www/go/test/main.go

Here, the development environment for Go has been built. Start coding~

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.