Three new books, Go Optimizations 101, Go Details & Tips 101 and Go Generics 101 are published now. It is most cost-effective to buy all of them through this book bundle in the Leanpub book store.

GoTV

GoTV is an abbreviation of Go Toolchain Version. It is a tool used to manage and use multiple coexisting installations of official Go toolchain versions harmoniously and conveniently.

Project page: https://github.com/go101/gotv

Please follow @Go100and1 to get the latest news of GoTV (and all kinds of Go details/facts/tips/...).

Installation

Run

go install go101.org/gotv@latest

to install GoTV.

A 1.17+ toolchain version is needed to finish the installation. The toolchain version may be uninstalled after pinning a suitable toolchain version (see below).

Usage

Run gotv without any arguments to show help messages.

Most gotv commands are in the following format:

gotv ToolchainVersion [go-arguments...]

During running the first such a command, the Go git repository will be cloned (which needs several minutes to finish).

ToolchainVersion might be

Examples:

$ gotv 1.17. version
[Run]: $HOME/.cache/gotv/tag_go1.17.13/bin/go version
go version go1.17.13 linux/amd64

$ gotv 1.18.3 version
[Run]: $HOME/.cache/gotv/tag_go1.18.3/bin/go version
go version go1.18.3 linux/amd64

$ cat main.go
package main

const A = 3

func main() {
	const (
		A = A + A
		B
	)
	println(A, B)
}

$ gotv 1.17. run main.go
[Run]: $HOME/.cache/gotv/tag_go1.17.13/bin/go run main.go
6 6

$ gotv 1.18.3 run main.go
[Run]: $HOME/.cache/gotv/tag_go1.18.3/bin/go run main.go
6 12

Other gotv commands:

# sync the Go git repository
gotv fetch-versions

# list all versions seen locally
gotv list-versions

# build and cache some toolchain versions
gotv cache-version ToolchainVersion [ToolchainVersion ...]

# uncache some toolchain versions to save disk space
gotv uncache-version ToolchainVersion [ToolchainVersion ...]

# pin a specified toolchain version at a stable path
gotv pin-version ToolchainVersion

# unpin the current pinned toolchain version
gotv unpin-version

Pin a toolchain version

We can use the gotv command to pin a specific toolchain version to a stable path. After adding the stable path to the PATH environment veriable, we can use the official go command directly. And after doing these, the toolchain versions installed through ways other than GoTV may be safely uninstalled.

It is recommanded to pin a 1.17+ version for bootstrap purpose. The following example shows how to pin Go toolchain version 1.17.13:

$ gotv pin-version 1.17.
[Run]: cp -r $HOME/.cache/gotv/tag_go1.17.13 $HOME/.cache/gotv/pinned-toolchain

Please put the following shown pinned toolchain path in
your PATH environment variable to use go commands directly:

	/home/username/.cache/gotv/pinned-toolchain/bin

After the prompted path is added to the PATH environment variable, open a new terminal window:

$ go version
go version go1.17.13 linux/amd64

Set a bootstrap toolchain version

To build a toolchain verision, another already built toolchain version is needed to be used in the building process. The other toolchain version is called the bootstrap version.

Some facts:

Currently, GoTV uses the toolchain set in the PATH environment variable as the bootstrap version by default. If GOROOT_BOOTSTRAP environment variable is set, then its value will be used.


The Go 101 project is hosted on Github. Welcome to improve Go 101 articles by submitting corrections for all kinds of mistakes, such as typos, grammar errors, wording inaccuracies, description flaws, code bugs and broken links.

If you would like to learn some Go details and facts every serveral days, please follow Go 101's official Twitter account @go100and1 or join Go 101 slack channels.

Tapir, the author of Go 101, has been on writing the Go 101 series books and maintaining the go101.org website since 2016 July. New contents will be continually added to the book and the website from time to time. Tapir is also an indie game developer. You can also support Go 101 by playing Tapir's games (made for both Android and iPhone/iPad):
Individual donations via PayPal are also welcome.