Simple go version manager, gluten-free.
Existing version managers often build Go from source, require a specific shell, pollute your environment with shims and functions, or bring a large plugin ecosystem you might not need.
g aims to be as unobtrusive and portable as possible: one readable shell script, official prebuilt Go archives, no privileged install, and just a pair of idiomatic Go env variables to get you setup.
g is inspired by tj/n - which I have contributed to in the past - and borrows some of its code.
- Get started with Go with a single line using the install script.
- Quickly install new versions using official prebuilt Go archives.
- Run any go version on demand without changing the active one.
- Colorful and interactive TUI but safe to pipe and use in automated scripts.
- Trusted: install and use Go versions as an unprivileged user; no
sudo. - Discover new Go versions including unstable beta and RC releases.
- Faster downloads by picking a mirror closer to you.
- A single, portable POSIX script that works across all common shells without shims.
- Transparent:
gis a shell script you can inspect, copy, and patch.
- macOS, Linux, BSD, or WSL.
- A POSIX-compatible shell.
- Either
curlorwget. sha256sum,shasum, oropenssl.
You most likely have them all already.
Before running any script, read it first: https://github.com/stefanmaric/g/releases/latest/download/install
Then install with curl:
curl -fsSL https://github.com/stefanmaric/g/releases/latest/download/install | shOr with wget:
wget -qO- https://github.com/stefanmaric/g/releases/latest/download/install | shg uses the standard Go environment variables. The installer defaults to:
GOROOT=$HOME/.go
GOPATH=$HOME/go$GOPATH/bin must be on PATH because that is where g and the active go binary live.
The installer downloads g to $GOPATH/bin/g, makes it executable, and updates your shell startup file with GOROOT, GOPATH, and $GOPATH/bin in PATH.
Restart your shell after installation so the new environment is loaded.
Skip all prompts and assume "yes", will install the lastest Go version right away:
curl -fsSL https://github.com/stefanmaric/g/releases/latest/download/install | sh -s -- -yConfigure a specific shell:
curl -fsSL https://github.com/stefanmaric/g/releases/latest/download/install | sh -s -- zshConfigure more than one shell:
curl -fsSL https://github.com/stefanmaric/g/releases/latest/download/install | sh -s -- fish bash zshThe installer supports bash, zsh, fish, ash, dash, csh, and tcsh.
If g is already used as a shell alias, the installer can configure an alternative alias.
To choose different defaults, set GOROOT and GOPATH before installing:
export GOROOT=$HOME/.local/share/golang
export GOPATH=$HOME/go-projects
curl -fsSL https://github.com/stefanmaric/g/releases/latest/download/install | shFor fish:
set -gx GOROOT $HOME/.local/share/golang
set -gx GOPATH $HOME/go-projects
curl -fsSL https://github.com/stefanmaric/g/releases/latest/download/install | sh- Configure the relevant variables in your shell initialization script
- Set
GOROOTandGOPATH. - Add
$GOPATH/bintoPATH.
- Set
- Copy
bin/gto$GOPATH/bin/gor another directory on yourPATH. - Make it executable:
chmod +x "$GOPATH/bin/g"
Install the latest stable Go release and make it active:
g install latestInstall and use a specific version:
g install 1.22.2List what you have installed already:
g listList available Go versions:
g list-allRun a specific version without changing the active one:
g run 1.22.2 versionRemove an old version:
g remove 1.21.9Run g with no command to open the interactive picker for installed versions.
Usage: g [COMMAND] [options] [args]
Commands:
g Open interactive UI with downloaded versions
g install latest Download and set the latest Go release
g install <version> Download and set Go <version>
g download <version> Download Go <version>
g set <version> Switch to Go <version>
g run <version> Run a given version of Go
g which <version> Output bin path for <version>
g remove <version ...> Remove the given version(s)
g prune Remove all versions except the current version
g list Output downloaded Go versions
g list-all Output all available remote Go versions
g self-upgrade Upgrade g to the latest version
g help Display help information, same as g --help
Options:
-h, --help Display help information and exit
-v, --version Output current version of g and exit
-q, --quiet Suppress almost all output
-c, --no-color Force disabled color output
-y, --non-interactive Prevent prompts
-o, --os Override operating system
-a, --arch Override system architecture
-u, --unstable Include unstable versions in list
--archive-url Override Go archive base URL
Aliases:
g install use
g download fetch
g run exec
g remove rm, uninstall
g list ls
g list-all ls-remote, list-remote
g self-upgrade self-update
By default, g detects your operating system and architecture from the current machine. Use --os and --arch to override that target:
g install 1.22.2 --os linux --arch amd64This is useful when you need a different Go build, for example an amd64 Go on Apple Silicon. If the same version is already installed and you install it again with a different explicit architecture, g replaces it.
By default, archives are downloaded from https://dl.google.com/go.
Use --archive-url to download archives from a mirror:
g install latest --archive-url https://golang.google.cn/dlOr set a default with G_GO_ARCHIVE_URL:
export G_GO_ARCHIVE_URL=https://golang.google.cn/dl
g install latestArchive-only mirrors also work as long as they serve official Go archive filenames:
export G_GO_ARCHIVE_URL=https://mirrors.aliyun.com/golang
g install 1.22.2Mirror downloads are still verified against the official Go checksum before extraction.
If g was installed with the installer, upgrade it with:
g self-upgradeTo remove only g, delete the executable:
# If you're using bash, zsh, or other POSIX shell:
rm "$(command -v g)"
# If you're using fish:
rm (command -v g)To remove Go versions installed by g, remove $GOROOT after backing up anything important:
rm -r "$GOROOT"If you used the installer, also delete the g-install line from your shell startup file. Common locations are:
~/.bash_profile bash on macOS
~/.bashrc bash on Linux/BSD
~/.zshrc zsh
~/.config/fish/config.fish fish
~/.cshrc csh
~/.tcshrc tcsh
$ENV ash or dash
g is intentionally small: one POSIX shell script, official prebuilt archives, checksum verification, and minimal shell setup. Other tools may be a better fit if you want project-local version files, a plugin ecosystem, Windows-first support, or source builds.
| Project | Good fit when | Tradeoff compared with g |
|---|---|---|
| moovweb/gvm | You want a full-featured Go environment manager. | Builds Go from source and has more moving parts. |
| syndbg/goenv | You like the rbenv/pyenv style. |
Uses shims and a heavier shell integration model. |
| hit9/oo | You want a source-based Go manager with a small interface. | Builds from source instead of using official archives. |
| asdf-golang | You already use asdf. |
Requires the asdf plugin system. |
| andrewkroh/gvm | You want Bash, Batch, and PowerShell workflows. | Less shell-agnostic and uses a different workflow. |
| MakeNowJust/govm | You want a minimal manager and do not mind source builds. | Builds from source and has extra runtime requirements. |
| kevincobain2000/gobrew | You want a Go-written manager with Windows support and extra conveniences. | Larger tool with its own root layout and shell setup. |
golang.org/dl |
You want the official wrapper commands for specific Go versions. | Installs one wrapper per version and does not manage switching for you. |
Use g if you want something that stays close to how Go itself is distributed:
download official archives, verify them, and switch versions without much fuss.
Please read CONTRIBUTING.md. ♥
- Every contributor to this project.
- The
nproject, whichgis inspired by and based on. - The
n-installproject, whichgis also based on.
MIT ♥
