brewでGo言語をインストール
A Tour of Goを進んでいくと、HTTPサーバの例が。お、Playgroundで通信ができるのか?と思ったら、案の定、ローカルで実行せよとのこと。
というわけで、brewでインストール。
$ brew update $ brew install go ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/go-1.3.1.mavericks.bottle.1.tar ######################################################################## 100.0% ==> Pouring go-1.3.1.mavericks.bottle.1.tar.gz ==> Caveats As of go 1.2, a valid GOPATH is required to use the `go get` command: http://golang.org/doc/code.html#GOPATH `go vet` and `go doc` are now part of the go.tools sub repo: http://golang.org/doc/go1.2#go_tools_godoc To get `go vet` and `go doc` run: go get code.google.com/p/go.tools/cmd/godoc go get code.google.com/p/go.tools/cmd/vet You may wish to add the GOROOT-based install location to your PATH: export PATH=$PATH:/usr/local/opt/go/libexec/bin Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completion has been installed to: /usr/local/share/zsh/site-functions ==> Summary /usr/local/Cellar/go/1.3.1: 4341 files, 114M
コメントに従って、.bash_profileに環境変数の設定を追加。
export GOPATH=$HOME/go export GOROOT=/usr/local/opt/go/libexec export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
bashの補完も効くようなので、続けてbash-completionをインストール。
$ brew install bash-completion ==> Downloading http://bash-completion.alioth.debian.org/files/bash-completion-1.3.tar.bz2 ######################################################################## 100.0% ==> Patching patching file bash_completion ==> ./configure --prefix=/usr/local/Cellar/bash-completion/1.3 ==> make install ==> Caveats Add the following lines to your ~/.bash_profile: if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi Homebrew's own bash completion script has been installed to /usr/local/etc/bash_completion.d Bash completion has been installed to: /usr/local/etc/bash_completion.d ==> Summary /usr/local/Cellar/bash-completion/1.3: 188 files, 1.1M, built in 6 seconds
こちらもコメントに従って.bash_profileに次の記述を追加。ちゃんと補完が効くようになった。
if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi
デフォルトでパッケージ管理システムが組み込まれている訳ね。ドキュメントをインストールしておく。Mercurialを使うので、これも前もってbrew install hgで入れておく。環境変数GOROOT以下にgodocというコマンドがインストールされた。
$ go get code.google.com/p/go.tools/cmd/godoc
はい、ちゃんとHTTPサーバの例題が動きましたとさ。
$ go build 57.go $ ./57
また、"code.google.com/p/go-tour/wc"のようなパッケージをimportしている例題もあるけど、これをローカルで動かすときは、これもgo getしてくればよい。
$ go get code.google.com/p/go-tour/wc
$GOPATH/src以下にソースコードが、$GOPATH/pkg以下に*.a形式のバイナリパッケージが配置される。
ということで今日は#58まで。
ちなみにCentOS 7のパッケージではGo 1.2になるようだ。