Go language version management tool gvm installation [macOS Edition]

Tadashi Shigeoka ·  Thu, January 24, 2019

I’ll introduce the procedure to install the Go language version management tool gvm and install golang with version specification.

golang

Prerequisites

  • macOS Mojave

gvm installation

$ zsh < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Cloning from https://github.com/moovweb/gvm.git to /Users/yourname/.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/yourname/.gvm/scripts/gvm`

Installing specific versions of Golang

Here’s how to install Golang with version specification using gvm:

$ gvm install go1.11 --binary
Installing go1.11 from binary source

Without various preparations, the following error occurs, so I basically specify —binary when installing.

ERROR: Failed to use installed version

Running gvm install version-number directly will cause an error.

$ gvm install go1.11
Downloading Go source...
Installing go1.11...
 * Compiling...
/Users/yorname/.gvm/scripts/install: line 84: go: command not found
ERROR: Failed to compile. Check the logs at /Users/yorname/.gvm/logs/go-go1.11-compile.log
ERROR: Failed to use installed version

Details were written in MacOS Sierraでgvmを使ってGo 1.8をセットアップ - Qiita. Thank you.

How to use specific Golang versions

You can switch to the desired golang version with gvm use version-number.

# Before gvm use
$ which go
go not found

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

# After gvm use
$ which go
/Users/yourname/.gvm/gos/go1.11/bin/go

# Check environment variables
$ echo $GOROOT
/Users/yourname/.gvm/gos/go1.11
$ echo $GOPATH
/Users/yourname/.gvm/pkgsets/go1.11/global

That’s all from the Gemba where I want to install and use multiple versions of golang with gvm.