Help us shape the future of Go! Take the 2026 Go Developer Survey

goversion

module
v0.0.0-...-44aab44 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT

README

goversion

Print the latest released Go version and the one installed locally.

CI Go Reference

Why

Knowing whether your local toolchain is current is a small but recurring question — when triaging build issues, before opening a PR, or in CI gates. goversion answers it in one line, with no surprises and no dependencies beyond Go itself.

Install

go install github.com/olivere/goversion/cmd/goversion@latest

(Tagged binary releases will follow once the tool stabilises.)

Usage

$ goversion
Latest:    go1.24.2
Installed: go1.23.4

JSON for scripts:

$ goversion -json
{"latest":"go1.24.2","installed":"go1.23.4"}

CI gate — exit 1 if your installed Go is older than upstream:

$ goversion -check && echo "up to date"

When go isn't on PATH, goversion says so plainly rather than guessing:

$ env -i PATH= goversion
note: 'go' not found on PATH
Latest:    go1.24.2
Installed: <not installed>

Other flags:

Flag Default Purpose
-timeout DUR 10s Network timeout for the latest-version lookup
-json off Emit {"latest":"…","installed":"…"} on stdout
-check off Exit 1 if installed Go is older than latest
-version — Print goversion's own version and exit

Exit codes

Code Meaning
0 Success (and, with -check, installed ≥ latest)
1 -check set and installed Go is older than latest
2 Operational failure (network, missing go, malformed flag, etc.)

Stderr is reserved for diagnostics; stdout carries data only. In -json mode, stdout is JSON only.

How it works

  • Latest version comes from https://go.dev/VERSION?m=text — the tooling-friendly endpoint the Go installer scripts hit. The first line of the response is the bare version (e.g. go1.24.2); we validate the format before printing it.
  • Installed version comes from invoking go version and parsing its output. We do not fall back to runtime.Version(): that constant reports the toolchain that compiled goversion itself, not whatever Go you have installed today, so substituting it would be a lie. When go isn't on PATH we say so explicitly and exit 2.

Development

goversion/
├── cmd/goversion/      # CLI entrypoint
├── internal/latest/    # go.dev fetcher
├── internal/local/     # `go version` parser
└── internal/semver/    # tiny "goX.Y[.Z][pre]" parser for -check
make test    # go test -race ./...
make lint    # go vet + staticcheck (if installed)
make build   # produces ./bin/goversion
make install # go install ./cmd/goversion

Contributing

Issues and pull requests are welcome at https://github.com/olivere/goversion. Please run make test and make lint before opening a PR.

License

MIT — see LICENSE.

Directories

Path Synopsis
cmd
goversion command
Command goversion prints the latest released Go version (from go.dev) and the version installed locally (from `go version`).
Command goversion prints the latest released Go version (from go.dev) and the version installed locally (from `go version`).
internal
latest
Package latest fetches the latest stable Go release version from go.dev.
Package latest fetches the latest stable Go release version from go.dev.
local
Package local detects which Go toolchain is installed on the host by invoking `go version`.
Package local detects which Go toolchain is installed on the host by invoking `go version`.
semver
Package semver parses and compares Go release versions of the form "goX.Y", "goX.Y.Z", or "goX.Y[.Z]<pre>" (e.g.
Package semver parses and compares Go release versions of the form "goX.Y", "goX.Y.Z", or "goX.Y[.Z]<pre>" (e.g.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL