Go Version Manager – GVM

What is GVM?

The Language Version Manager (GVM) is an open-source tool for managing Go locales. Gvm pkgsets supports installing multiple versions of Go and managing modules for each project. Josh Bussdieker initially developed it; GVM and Ruby RVM. It allows you to create a development environment for projects. Furthermore, it separates different Go versions and packages dependencies to provide more flexibility in case of issues caused by different versions. GVM mainly have the following characteristics:

  • Manage multiple versions of Go, including installing, uninstalling, and specifying a Go version for use
  • View all official Go versions available locally installed and default Go versions
  • Manage multiple, GOPATH editable Go environment variables
  • can associate the current directory with GOPATH
  • You can view the file differences GOROOT under
  • Support Go version switching

Install GVM

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

GVM Function Preview

$ gvm
Usage: gvm [command]

  GVM is the Go Version Manager

  version    - print the gvm version number
  get        - gets the latest code (for debugging)
  use        - select a go version to use (--default to set permanently)
  diff       - view changes to Go root
  help       - display this usage text
  implode    - completely remove gvm
  install    - install go versions
  uninstall  - uninstall go versions
  cross      - install go cross compilers
  linkthis   - link this directory into GOPATH
  list       - list installed go versions
  listall    - list available versions
  alias      - manage go version aliases
  pkgset     - manage go packages sets
  pkgenv     - edit the environment for a package set

Using GVM

  • View all versions of Go
$ gvm listall
gvm gos (available)
  • Install a version of Go
$ gvm listall
$ gvm install go1.18beta1
Updating Go source...
Installing go1.18beta1...
 * Compiling...
go1.18beta1 successfully installed!
  • Use a version of Go
# Temporarily effective
$ gvm use go1.18beta1

# Permanent effect
gvm use go1.18beta1 --default
  • View the current version
$ gvm list
gvm gos (installed)
= > go1.17 #represents the version currently in use

Set global go env

  • Modification of .bashrc
$ nano .bashrc
export GOPATH=/Users/xxx/xx
export GOBIN=$GOPATH/bin
# GoEnv
export GOENV=$GOPATH/env
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io,direct
# go module
export GO111MODULE=auto