gvmを使うとGoをバージョン指定してインストールできる。
https://github.com/moovweb/gvm
以下、Macにインストールするのを前提とする。
依存ツールのインストール
➤ brew update
➤ brew install mercurial
gvmのインストールは
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
または
zsh < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
なんだけど、このままではfishではエラーになり使えない。
そこでこのIssueを見ると解決方法が書いてあった。
https://github.com/moovweb/gvm/issues/137
fishermanというfishのプラグインマネージャーを使ってbassプラグインをインストールすれば解決できるらしい。
fishermanインストール
➤ curl -Lo ~/.config/fish/functions/fisher.fish --create-dirs git.io/fisher
bassをインストール
➤ fisher edc/bass
gvmをインストール
bashに切り替えて
➤ bash
bash-3.2$ bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source /Users/username/.gvm/scripts/gvm
実行し、
config.fishに以下を追記して設定反映すれば、gvmコマンドを使うことができる。
function gvm
bass source ~/.gvm/scripts/gvm ';' gvm $argv
end
Go1.6をインストール
本当は1.8を使いたいところだけど、1.6をインストール
➤ gvm install go1.6
ERROR: Failed to compile. Check the logs at /Users/koori/.gvm/logs/go-go1.6-compile.log
ERROR: Failed to use installed version
exit code: 1
1.5からはセルフホスティングされているため、ビルドに1.4以上が必要らしい・・・あんまりこの辺は理解していない。
バイナリからインストール
➤ gvm install go1.4 -B
Installing go1.4 from binary source
➤ gvm use go1.4
➤ set -x GOROOT_BOOTSTRAP GOROOT
Go1.6をインストール
➤ gvm install go1.6 -B
Installing go1.6 from binary source
➤ gvm use go1.6
Now using version go1.6
確認してみる
➤ gvm list
gvm gos (installed)
go1.4
go1.6
➤ go version
go version go1.6 darwin/amd64
OK