MacにGo言語環境をセットアップする
環境
Goをインストール
Homebrewを利用してインストールする
$ brew install go ==> Downloading https://homebrew.bintray.com/bottles/go-1.10.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring go-1.10.high_sierra.bottle.tar.gz ==> Caveats A valid GOPATH is required to use the `go get` command. If $GOPATH is not specified, $HOME/go will be used by default: https://golang.org/doc/code.html#GOPATH You may wish to add the GOROOT-based install location to your PATH: export PATH=$PATH:/usr/local/opt/go/libexec/bin ==> Summary 🍺 /usr/local/Cellar/go/1.10: 8,150 files, 336.9MB
インストール後の確認
$ go version go version go1.10 darwin/amd64
Hello Worldしてみる
hello.goファイルを作成し、実行する
# 名前空間のようなもの package main # fmtパッケージ:C言語のprintfおよびscanfと似た関数を持つ import "fmt" func main() { fmt.Printf("hello, world\n") }
実行
$ go run hello.go hello, world
おしまい!