Simple go version manager, gluten-free.
Existing version managers build go from source, have too many dependencies, pollute the PATH, and/or require you to use a specific shell environment.
g aims to be as unobtrusive and portable as possible.
g is inspired by tj/n - which I have contributed to in the past - and borrows some of its code.
$GOROOTare exported which...
goand not specific to
sourcefunctions in your shell config.
wgetfirst-class support alike.
wget, check with
Not strictly necessary, but highly recommended, to completely remove any previous go installation — just to prevent any weird outcome.
IMPORTANT: Before you continue, I encourage you to read the install script; never trust someone telling you to run random commands.
That said, you can install
g with a single command:
curl -sSL https://git.io/g-install | sh -s
If you use
wget -qO- https://git.io/g-install | sh -s
That will download the
g script, put it inside
$GOPATH/bin/, give it execution rights with
chmod, and configure your default shell's initialization file, setting the
GOROOT environment variables and adding
$GOPATH/bin to the
Then you will prompted to install the latest version of go; you can skip this step and install your preferred version with
NOTE: You must restart your current shell session for it to read these new env vars in order to use
The install script currently supports the following shells:
That doesn't mean you cannot use
g with other shells, just proceed with the manual installation.
The install script is going to select your default shell for configuration. You might see what your default shell is by running:
If you wish to configure a diff shell, you might pass it as arguments:
curl -sSL https://git.io/g-install | sh -s -- fish
You might as well configure several shells, but that's usually not required:
curl -sSL https://git.io/g-install | sh -s -- fish bash zsh
-y option to skip the prompts and assume "yes" for everything:
curl -sSL https://git.io/g-install | sh -s -- -y
By default, these go environment variables are used:
GOROOT: $HOME/.go GOPATH: $HOME/go
$GOPATH/bin is added to the
PATH and there's where
g is copied to.
You might set those variables before running the install script. For example, in bash and zsh:
export GOROOT=~/.local/share/golang export GOPATH=~/MyProjects/go-projects curl -sSL https://git.io/g-install | sh -s
set -gx GOROOT ~/.local/share/golang set -gx GOPATH ~/MyProjects/go-projects curl -sSL https://git.io/g-install | sh -s
$GOROOTenvironment variables and add
./bin/gscript and put it anywhere available in your
$GOPATH/bin/is a good option.
chmod +x $GOPATH/bin/g.
g includes a
self-upgrade command you can run to get the latest version of
g. This command simply runs the install script once again.
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 Upgrades 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
g is a single portable shell script that acts like a binary that's available in your
$PATH. If you setup
g with the install script, its removal should be pretty straight forward.
First of all, get some info about your system:
echo $SHELL echo $GOROOT echo $GOPATH command -v g
You will notice the
g file lives inside your
$GOPATH/bin/ directory. If you only want to remove
g and keep your currently installed
go binaries and related files, simply delete
# If you're using bash, zsh, or other POSIX shell: rm "$(command -v g)" # If you're using fish: rm (command -v g)
Now, if you want to remove everything, first be sure to backup your projects inside
$GOROOT, if any. Then remove everything inside
rm -r $GOPATH $GOROOT
Then open your shell config file with your text editor of choice and look of for a line that includes
g-install to remove it. These are the locations usually used by the install script:
# bash on MacOS ~/.bash_profile # bash on linux/BSD ~/.bashrc # zsh ~/.zshrc # fish shell ~/.config/fish/config.fish # csh ~/.cshrc # tcsh ~/.tcshrc # For ash and dash, check your $ENV var echo $ENV
At this point you would have removed
g install <version>, maybe
set. See #8
installonly for install and remove the
galready exists, mainly
g-installoffers the user to setup an alternative alias for
self-upgradecommand throw if
gwas not installed in the common way
completecommand that generates completions for the supported shells
g-installsetup the shells to call this command for completions
goenvbefore installing a new version of go.
Please read CONTRIBUTING.md. ♥
gis inspired by and based on.
gis also based on.