DEV Community

kingyou
kingyou

Posted on

how to use GVM (Go Version Manager)

How to Use GVM (Go Version Manager)

GVM (Go Version Manager) is a tool that allows developers to easily install, manage, and switch between multiple versions of the Go programming language on a single system. It simplifies handling different Go versions for different projects without conflicts.

Installing GVM

To install GVM on your system, follow these steps:

  • First, install the required dependencies:
  sudo apt-get install curl git mercurial make binutils bison gcc build-essential
Enter fullscreen mode Exit fullscreen mode
  • Next, install GVM using the official installer script:
  bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Enter fullscreen mode Exit fullscreen mode
  • If you use zsh instead of bash, replace bash with zsh in the command above.

After installation, restart your shell or source your profile to load GVM commands.

Installing and Using Go Versions

With GVM installed, you can manage Go versions easily:

  • List all available Go versions:
  gvm listall
Enter fullscreen mode Exit fullscreen mode
  • Install a specific Go version (for example, version 1.4):
  gvm install go1.4
Enter fullscreen mode Exit fullscreen mode
  • To use a specific installed Go version:
  gvm use go1.4 --default
Enter fullscreen mode Exit fullscreen mode

The --default flag sets this version as the default for new terminals.

  • Check which Go versions are installed on your machine:
  gvm list
Enter fullscreen mode Exit fullscreen mode
  • Uninstall a Go version if no longer needed:
  gvm uninstall go1.4
Enter fullscreen mode Exit fullscreen mode

Managing Go Packages with GVM

GVM supports managing package sets to isolate dependencies per Go version or project:

  • Create a new package set:
  gvm pkgset create mypkgset
Enter fullscreen mode Exit fullscreen mode
  • Switch to a package set:
  gvm pkgset use mypkgset
Enter fullscreen mode Exit fullscreen mode
  • List existing package sets:
  gvm pkgset list
Enter fullscreen mode Exit fullscreen mode

This feature helps in keeping project dependencies cleanly separated.

Additional Useful Commands

  • To link the current directory into your GOPATH for development:
  gvm linkthis
Enter fullscreen mode Exit fullscreen mode
  • To view all commands and usage information:
  gvm help
Enter fullscreen mode Exit fullscreen mode

GVM is particularly helpful for Go developers needing to maintain projects on different Go versions without the hassle of manual environment configurations. This tool automatically manages your $GOROOT and $GOPATH environment variables when switching versions, streamlining your Go development workflow.

For detailed usage and latest updates, visit the official GVM GitHub repository.


This guide will get you started with GVM for easy Go version management in your development environment. Happy coding!

Top comments (0)