安装
$ brew install go
检查
$ go version
配置路径
打开文件$ vim ~/.bash_profile
GOROOT=/usr/local/Cellar/go/1.10.1/libexec export GOROOT export GOPATH=/Users/yourname/mygo export GOBIN=$GOPATH/bin export PATH=$PATH:$GOBIN:$GOROOT/bin
说明:
GOROOT: go安装目录
GOPATH:go工作目录
src目录: go的源文件
pkg目录: 编译好的库文件,主要是*.a文件;
bin目录: 可执行文件
GOBIN:go可执行文件目录
PATH:go可执行文件
生效$ source ~/.bash_profile
查看配置$ go env
IDE GoLand:
https://www.jetbrains.com/go/download
激活服务器:
hello.go
package main import ( "fmt" ) func main() { fmt.Println("hello go!") }
运行
go run hello.go
编译和链接生成可执行文件
go build hello.go
运行可执行文件
./hello