macOSにGVM(Golang)をインストール

macOSにGVMでGoをインストールする方法です。

GVMインストール

Mac OS X Requirements

$ bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Cloning from https://github.com/moovweb/gvm.git to /Users/user/.gvm
No existing Go versions detected
Installed GVM v1.0.22

Please restart your terminal session or to get started right away run
 `source /Users/user/.gvm/scripts/gvm`

$ source /Users/user/.gvm/scripts/gvm

$ gvm version
Go Version Manager v1.0.22 installed at /Users/user/.gvm

Goの利用可能なバージョンを確認

$ gvm list

gvm gos (installed)

$ gvm listall

gvm gos (available)

   go1
   go1.0.1
   go1.0.2
   go1.0.3
   go1.1
   go1.1.1
   go1.1.2
   go1.10
   go1.10.1
   go1.10beta1
   go1.10beta2
   go1.10rc1
   go1.10rc2
   ...

Go1.4をインストール

Go1.5+のコンパイルのために、Go1.4をインストールします。

$ gvm install go1.4 -B
Installing go1.4 from binary source

$ gvm use go1.4
Now using version go1.4

$ go version
go version go1.4 darwin/amd64

$ export GOROOT_BOOTSTRAP=$GOROOT

A Note on Compiling Go 1.5

Go1.10.1をインストール

コンパイルエラーが発生します。

$ gvm install go1.10.1
Installing go1.10.1...
 * Compiling...
ERROR: Failed to compile. Check the logs at /Users/user/.gvm/logs/go-go1.10.1-compile.log
ERROR: Failed to use installed version

$ cat /Users/user/.gvm/logs/go-go1.10.1-compile.log
Building Go cmd/dist using /Users/user/.gvm/gos/go1.4.
Building Go toolchain1 using /Users/user/.gvm/gos/go1.4.
failed MSpanList_Insert 0x129c790 0x3005ba1e8f9a4 0x0
fatal error: MSpanList_Insert

Bフラグ付きでGo1.10.1をインストール

Bフラグ付きでインストールできたというコメントがあるので、試します。

Can you try installing 1.9.2 with the -B flag? Just worked for a friend of mine who was having the same issue.

https://github.com/moovweb/gvm/issues/284#issuecomment-357138771

$ gvm install go1.10.1 -B
Installing go1.10.1 from binary source

$ gvm use go1.10.1
Now using version go1.10.1

$ go version
go version go1.10.1 darwin/amd64

無事Go1.10.1をインストールできました。

GVM2

ベータ版のようですが、GVM2もありました。
.go-version、.go-pkgset(.ruby-version、.ruby-gemsetに相当)が使えるようです。

タイトルとURLをコピーしました