fgm is a Go version manager written in Rust (macOS/Linux first). It supports downloading/installing, switching, listing, uninstalling, printing the current version, and cleaning cache.
- Install:
install <version>(supportsgo1.22.4/1.22.4/1.22/latest) - Switch:
use <version> - Current:
current - List installed:
list - Uninstall:
uninstall <version> - Latest stable:
latest - Cache:
cache dir|size|clean - Diagnose:
doctor
curl -fsSL https://raw.githubusercontent.com/coderbaozi/fgm/main/scripts/install.sh | shOptional environment variables:
FGM_BIN_DIR: default~/.local/bin
- Install and switch to a version:
fgm install 1.22 --use
fgm current- Ensure
PATHincludes the shim directory (default:~/.fgm/bin):
export PATH="$HOME/.fgm/bin:$PATH"- Switch versions:
fgm use 1.22.4
go versionlatest: fetch the latest stable tag viahttps://go.dev/VERSION?m=text(or an equivalent URL based on--mirror).1.22.4/go1.22.4: install the specified patch directly.1.22: resolve to the latest stable patch under the same minor (e.g.go1.22.4).- Resolution: request
{mirror}/?mode=json&include=all, filterstable=trueentries under the same minor, and pick the highest patch.
- Resolution: request
Root: ~/.fgm
~/.fgm/versions/<tag>/go: extracted Go installation directory~/.fgm/cache: download cache (.tar.gz)~/.fgm/current: symlink pointing to the current version~/.fgm/bin/go,~/.fgm/bin/gofmt: shims (symlinks tocurrent/go/bin/*)
--root <DIR>: setfgmroot directory (default:~/.fgm)--mirror <URL>: set download mirror (default:https://go.dev/dl)--quiet: reduce output--verbose: print more debug information
Example:
fgm --mirror https://go.dev/dl install 1.22 --use- SHA256 verification is enabled by default; use
install --no-verifyto skip. - If the target version already exists, use
install --forceto overwrite.
fgm doctor
fgm cache size
fgm cache clean- Windows is not supported for now (the shim relies on symlink).
- If the mirror specified by
--mirrordoes not support/dl/?mode=json,install 1.22cannot resolve the latest patch automatically (use the defaulthttps://go.dev/dlor a compatible mirror).