G is a command line tool under Linux, macOS and Windows, which can provide a convenient management and switching of multiple versions of go environment.

features

  • Support for listing the go versions available for installation
  • Support for listing installed GO versions
  • Local installation of multiple go versions is supported
  • Uninstall the installed GO version
  • Supports free switching between installed GO versions

The installation

Automatic installation

  • Linux/macOS (bash, ZSH)

    #It is recommended to clear environment variables such as' GOROOT 'and' GOBIN 'before installation
    $ wget -qO- https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
    $ echo "unalias g" >> ~/.bashrc # is optional. If another program (such as 'git') uses 'g' as an alias.
    $ source ~/.bashrc Source ~/.zshrc
    Copy the code

Manual installation

  • Download the binary compressed package of the corresponding platform.

  • Decompress the package to the PATH environment variable directory, for example, /usr/local/bin.

  • Edit shell environment configuration files (~/.bashrc, ~/.zshrc…)

    $ cat>>~/.bashrc<<EOF
    export GOROOT="${HOME}/.g/go"
    export PATH="${HOME}/.g/go/bin:$PATH"
    export G_MIRROR=https://golang.google.cn/dl/
    EOF
    Copy the code

use

Query the GO versions of stable states that are currently available for installation

$ g ls-remote stable
1.11.9
1.12.4
Copy the code

Install target GO version 1.12.4

$G the install 1.12.4
Installed successfully
$ go versionGo version go1.12.4 Darwin/amd64Copy the code

Query the installed GO version

$ g ls
1.12.4
Copy the code

Query all go versions available for installation

$ g ls-remote1 1.2.2 1.3 1.3.1... // Omit some versions 1.11.7 1.11.8 1.11.9 1.12 1.12.1 1.12.2 1.12.3 1.12.4Copy the code

Install target GO version 1.11.9

$G the install 1.11.9
Installed successfully
$ go versionGo version go1.11.9 Darwin/amd64Copy the code

Switch to another installed version of Go

$ g ls
1.11.9
1.12.4
$G the use 1.12.4Go version go1.12.4 Darwin/amd64Copy the code

Uninstall an installed version of Go

G uninstall 1.11.9 uninstall successfullyCopy the code

FAQ

  • What does the environment variable G_MIRROR do?

    With mainland China not freely access Golang website, which leads to the query and download go version is difficult, so you can through the environment variable specifies a mirror site (https://golang.google.cn/dl/), g will be downloaded from this site query, go version available.

  • Does source code compilation install support?

    Does not support

thanks

Thanks to NVM, N, RVM and other tools for providing valuable ideas.