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
homebrew
Mac 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
2.0 Create a Bash_profile Mac environment profile If it does not exist
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:
Problem:
If the open terminal does not take effect, append the above to the ~/.zshrc
middle:
Copy and paste save.