Install go under Mac and configure the appropriate environment

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

A lot of tutorials, but not complete, so I encountered a variety of problems in the installation process. Later, a combination of several tutorials to configure. I used two methods, and later removed one of them. Here are my installation steps:

Method One: Homebrew

homebrewMac system is currently the most used management software tools, currently supported go, can be directly installed through the command go, for later convenience, it should be git mercurial installed:

1234
Brew Update && Brew upgradebrew install gitbrew install mercurialbrew install go

This will go allow you to see the relevant information after installation by using the command line input. Enter go env View environment information:

123456789101112131415
Goarch= "AMD64" gobin= "gochar=" 6 "goexe=" "gohostarch=" AMD64 "gohostos=" Darwin "goos=" Darwin "Gopath=" "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 "

Method Two: Pkg package installation

Go directly to the official download installation package, and then double-click Install, and then enter go , go env , and go version so on to see if it is installed.

Environment variable Configuration

1.0 See if Bash_profile exists

1
CD ~/.bash_profile

2.0 Create a Bash_profile Mac environment profile If it does not exist

1
Vim ~/.bash_profile

3.0 Adding GO Environment variables
If this is the first installation method, you only need to specify a second GOPATH . In order for your program to be compiled and executed directly from anywhere on the command line, add GOPATH the following bin :

12345678
#This is my personal bash_profile,when loaded at login.#===2015-08-15=== #GOPATHexport gopath= $HOME/documents/go_ Workspace#gopath binexport path= $PATH: $GOPATH/bin

However, after the second method is installed, the input go is displayed ommand not found: go , so it needs to be specified in the .bash_profile GOROOT following bin :

12345678910111213
#This is my personal bash_profile,when loaded at login.#===2015-08-15=== #GOROOTexport goroot=/usr/local/go# Gopathexport gopath= $HOME/documents/go_workspace#goroot binexport path= $PATH: $GOROOT/bin#gopath binexport PATH=$ PATH: $GOPATH/bin

After the general environment variable is changed, the restart takes effect. The file is automatically executed when the terminal is restarted .bash_profile .

If you want to take effect immediately, you can execute the following statement:

1
$ source. bash_profile

Problem:

If the open terminal does not take effect, append the above to the ~/.zshrc middle:

1
OPEN-E ~/.ZSHRC

Copy and paste save.

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.