In Go project development, the team has to keep the development version consistent, how to quickly install and deploy and switch Go environment, here we recommend a tool GVM (Go Version Manager), it can easily switch and customize Go Path, Go Root and other parameters, is a real multi-version installation and management tool.

GVM, similar to RVM in ruby, can be used to easily manage Go versions. It has the following main features.

  • Managing multiple versions of Go, including installing, uninstalling, and specifying a particular version of Go to use.
  • View all officially available versions of Go, as well as view locally installed and default versions of Go in use.
  • Manage multiple GOPATHs and edit Go’s environment variables.
  • Ability to associate the current directory to GOPATH.
  • You can view file differences under GOROOT.

Installing

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

Or, if you are using zsh, just change bash with zsh.

Usage

Check the features supported by gvm.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  ~ gvm     
Usage: gvm [command]

Description:
  GVM is the Go Version Manager

Commands:
  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

Install Go version

For example, to install go1.13 version.

1
gvm install go1.13

View Go version

1
2
3
4
5
6
➜  ~ gvm list          

gvm gos (installed)

   go1.12
=> system

Switching Go versions

1
gvm use go1.***

Managing Gopath environments

GVM provides a relatively simple tool, gvm pkgset, to create environments that use GOPATH.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
➜  ~ gvm pkgset
= gvm pkgset

* http://github.com/moovweb/gvm
== DESCRIPTION:
GVM pkgset is used to manage various Go packages
== Usage
  gvm pkgset Command

== Command
  create     - create a new package set
  delete     - delete a package set
  use        - select where gb and goinstall target and link
  empty      - remove all code and compiled binaries from package set
  list       - list installed go packages

Uninstall

Uninstall an installed version of Go.

1
gvm uninstall go1.13