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.
GOPATH
Environment variables
GOPATH
Environment 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"