MAC Install Go language development environment

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

Reference http://www.cnblogs.com/houziwty/p/5708666.html

Http://docscn.studygolang.com/doc/install#osx

Official website: https://golang.org/

Download:

Download from official website,

or download from another connection: https://storage.googleapis.com/golang/go1.8.darwin-amd64.pkg

Installation

Default installation, the/usr/local/go directory is installed automatically

And the environment variables are set automatically.

Go env to view the current environment variables for Go

This go is going to do it.

GOPATHEnvironment variables

GOPATHEnvironment variables Specify the location of your workspace. It may be the only environment variable you need to set up when you develop the GO code.

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

See gopath= through Go env /users/li/go is the go directory on the user's home

now I'm building Gopath in/data/web/gowork . Note that it must never be the same as your go install directory

cd/data/web/

Midir gowork

Add the Bin directory of the Gopath to the environment variable

Echo $PATH

VI ~/.bash_profile

Add two lines:

Export gopath= "/data/web/gowork"

Export path= "/data/web/gowork/bin: $PATH"

If you want to take effect immediately after confirming that there is no problem, you can execute the following command

SOURCE ~/.bash_profile

Review the following PATH environment variables again

Echo $PATH

Tip, before modifying the path variable, echo $PATH once, in case you mistake or lost the value of the $path variable can be used to re-apply the printed value.

First Program

  

CD $GOPATH/SRC

mkdir Hellomygo

vim hellomygo/hellomygo.go

  

" FMT " Func Main () {        fmt. Printf ("Hello, my go\n")}

Go Install Hellomygo

LS $GOPATH/bin

The resulting Hellomygo executable file is displayed

Can be entered in any other directory Hellomygo will be displayed

"Hello, My Go"

Direct input running command go run hellomygo/hellomygo.go also display

  "Hello, My Go"

  

      

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.