モチベーション
go言語でビルドしていて、バージョンがマッチしていないとエラーになった。macOSのコンパイル環境で、go言語のバージョンを簡単に変更する方法は無いだろうか?
# math/bits
compile: version "go1.12.8" does not match go tool version "go1.12.9"
# errors
compile: version "go1.12.8" does not match go tool version "go1.12.9"
# runtime/internal/sys
compile: version "go1.12.8" does not match go tool version "go1.12.9"
# unicode/utf8
compile: version "go1.12.8" does not match go tool version "go1.12.9"
# internal/cpu
compile: version "go1.12.8" does not match go tool version "go1.12.9"
HomeBrew を使ってバージョンを確認
go言語のパッケージの詳細を見ると、どうも、切り替えられそうだ...
$ brew info go
go: stable 1.12.9 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://golang.org
/usr/local/Cellar/go/1.12.8 (9,816 files, 452.7MB)
Poured from bottle on 2019-08-15 at 22:49:03
/usr/local/Cellar/go/1.12.9 (9,819 files, 452.8MB) *
Poured from bottle on 2019-08-16 at 16:23:19
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb
==> Requirements
Required: macOS >= 10.10 ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 84,842 (30 days), 275,543 (90 days), 1,163,983 (365 days)
install_on_request: 65,340 (30 days), 211,527 (90 days), 863,599 (365 days)
build_error: 0 (30 days)
brew switch で切り替え
調べたところ、brew switch という機能があるらしい。
そこで、先ほど、リストされていたバージョンを指定してみる。
$ brew switch go 1.12.8
Cleaning /usr/local/Cellar/go/1.12.8
Cleaning /usr/local/Cellar/go/1.12.9
3 links created for /usr/local/Cellar/go/1.12.8
どうやら、切り替わったみたいだ
$ brew info go
go: stable 1.12.9 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://golang.org
/usr/local/Cellar/go/1.12.8 (9,816 files, 452.7MB) *
Poured from bottle on 2019-08-15 at 22:49:03
/usr/local/Cellar/go/1.12.9 (9,819 files, 452.8MB)
Poured from bottle on 2019-08-16 at 16:23:19
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb
==> Requirements
Required: macOS >= 10.10 ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 84,842 (30 days), 275,543 (90 days), 1,163,983 (365 days)
install_on_request: 65,340 (30 days), 211,527 (90 days), 863,599 (365 days)
build_error: 0 (30 days)
確認結果
確かに、go言語のバージョンが切り替わった
$ go version
go version go1.12.8 darwin/amd64