{"id":13525700,"url":"https://github.com/stefanmaric/g","last_synced_at":"2025-04-12T17:42:58.973Z","repository":{"id":37484222,"uuid":"128644798","full_name":"stefanmaric/g","owner":"stefanmaric","description":"Simple go version manager, gluten-free","archived":false,"fork":false,"pushed_at":"2023-07-10T18:19:16.000Z","size":2691,"stargazers_count":932,"open_issues_count":8,"forks_count":54,"subscribers_count":17,"default_branch":"next","last_synced_at":"2025-04-03T19:15:50.893Z","etag":null,"topics":["bash","cli","dependency-manager","environment","fish","gluten-free","go","golang","installer","linux","macos","portable","version-manager","zsh"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefanmaric.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-04-08T13:36:06.000Z","updated_at":"2025-04-03T12:27:11.000Z","dependencies_parsed_at":"2024-01-25T17:13:24.829Z","dependency_job_id":null,"html_url":"https://github.com/stefanmaric/g","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanmaric%2Fg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanmaric%2Fg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanmaric%2Fg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanmaric%2Fg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefanmaric","download_url":"https://codeload.github.com/stefanmaric/g/tar.gz/refs/heads/next","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248608539,"owners_count":21132745,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","cli","dependency-manager","environment","fish","gluten-free","go","golang","installer","linux","macos","portable","version-manager","zsh"],"created_at":"2024-08-01T06:01:21.201Z","updated_at":"2025-04-12T17:42:58.952Z","avatar_url":"https://github.com/stefanmaric.png","language":"Shell","funding_links":[],"categories":["Shell","golang","Version-Switch-Tools","Version Managers"],"sub_categories":["Go"],"readme":"# g\n\nSimple go version manager, gluten-free.\n\n\u003cdiv align=\"center\"\u003e\u003cimg src=\"screencast.webp\" alt=\"screencast\"\u003e\u003c/div\u003e\n\n## Why?\n\nExisting 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.\n\n`g` is inspired by [tj/n](https://github.com/tj/n) - which I have contributed to in the past - and borrows some of its code.\n\n## Features\n\n- Run any go version on demand.\n- Single portable shell script that ideally lives where your go binaries live.\n- Works no matter what shell you use as long as `$GOPATH` and `$GOROOT` are exported which...\n- ...is idiomatic to `go` and not specific to `g`.\n- No need to `source` functions in your shell config.\n- Downloads pre-built binaries so it is fast and...\n- ...requires no git, no mercurial, no gcc, no xcode, etc.\n- `curl` and `wget` first-class support alike.\n- Colorful UI and interactive but safe to pipe and use in automated scripts.\n- self-upgrade command to keep up-to-date.\n- Option to get go beta versions.\n- Get started in golang with a single line using the install script.\n- The install script detects name collisions and helps you set an alternative name.\n\n## Requirements\n\n- macOS, Linux or BSD environment. [Bash for Windows (WSL)](https://docs.microsoft.com/en-us/windows/wsl/about) is supported as well.\n- Either [`curl`](https://en.wikipedia.org/wiki/CURL) or [`wget`](https://en.wikipedia.org/wiki/Wget), check with `curl -V` or `wget -V` respectively.\n\nNot strictly necessary, but highly recommended, to completely remove any previous go installation — just to prevent any weird outcome.\n\n## Single-line Installation\n\n**IMPORTANT**: Before you continue, I encourage you to [read the install script](https://git.io/g-install); never trust someone telling you to run random commands.\n\nThat said, you can install `g` with a single command:\n\n```shell\ncurl -sSL https://git.io/g-install | sh -s\n```\n\nIf you use `wget` instead:\n\n```shell\nwget -qO- https://git.io/g-install | sh -s\n```\n\nThat will download the [`g` script](./bin/g), put it inside `$GOPATH/bin/`, give it execution rights with `chmod`, and configure your default shell's initialization file, setting the `GOPATH` \u0026 `GOROOT` environment variables and adding `$GOPATH/bin` to the `PATH`.\n\nThen you will prompted to install the latest version of go; you can skip this step and install your preferred version with `g` later.\n\n**NOTE**: You must restart your current shell session for it to read these new env vars in order to use `g` or `go`.\n\n### Shell support\n\nThe install script currently supports the following shells:\n\n- bash\n- zsh\n- fish\n- ash\n- dash\n- csh\n- tcsh\n\nThat doesn't mean you cannot use `g` with other shells, just proceed with the [manual installation](#manual-installation).\n\nThe install script is going to select your default shell for configuration. You might see what your default shell is by running:\n\n```shell\necho $SHELL\n```\n\nIf you wish to configure a diff shell, you might pass it as arguments:\n\n```shell\ncurl -sSL https://git.io/g-install | sh -s -- fish\n```\n\nYou might as well configure several shells, but that's usually not required:\n\n```\ncurl -sSL https://git.io/g-install | sh -s -- fish bash zsh\n```\n\nUse the `-y` option to skip the prompts and assume \"yes\" for everything:\n\n```shell\ncurl -sSL https://git.io/g-install | sh -s -- -y\n```\n\n### Changing defaults\n\nBy default, these go environment variables are used:\n\n```\nGOROOT: $HOME/.go\nGOPATH: $HOME/go\n```\n\n`$GOPATH/bin` is added to the `PATH` and there's where `g` is copied to.\n\nYou might set those variables before running the install script. For example, in bash and zsh:\n\n```shell\nexport GOROOT=~/.local/share/golang\nexport GOPATH=~/MyProjects/go-projects\ncurl -sSL https://git.io/g-install | sh -s\n```\n\nIn fish:\n\n```shell\nset -gx GOROOT ~/.local/share/golang\nset -gx GOPATH ~/MyProjects/go-projects\ncurl -sSL https://git.io/g-install | sh -s\n```\n\n## Manual Installation\n\n1. Make sure to export the `$GOPATH` \u0026 `$GOROOT` environment variables and add `$GOPATH/bin` to your `PATH`.\n2. Grab a copy of the [`./bin/g`](./bin/g) script and put it anywhere available in your `PATH` — inside `$GOPATH/bin/` is a good option.\n3. Give the script execution rights with `chmod +x $GOPATH/bin/g`.\n4. Restart your shell session to make sure the env variables are loaded.\n\n## Upgrading\n\n`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.\n\n## Usage\n\n```\n  Usage: g [COMMAND] [options] [args]\n\n  Commands:\n\n    g                         Open interactive UI with downloaded versions\n    g install latest          Download and set the latest go release\n    g install \u003cversion\u003e       Download and set go \u003cversion\u003e\n    g download \u003cversion\u003e      Download go \u003cversion\u003e\n    g set \u003cversion\u003e           Switch to go \u003cversion\u003e\n    g run \u003cversion\u003e           Run a given version of go\n    g which \u003cversion\u003e         Output bin path for \u003cversion\u003e\n    g remove \u003cversion ...\u003e    Remove the given version(s)\n    g prune                   Remove all versions except the current version\n    g list                    Output downloaded go versions\n    g list-all                Output all available, remote go versions\n    g self-upgrade            Upgrades g to the latest version\n    g help                    Display help information, same as g --help\n\n  Options:\n\n    -h, --help                Display help information and exit\n    -v, --version             Output current version of g and exit\n    -q, --quiet               Suppress almost all output\n    -c, --no-color            Force disabled color output\n    -y, --non-interactive     Prevent prompts\n    -o, --os                  Override operating system\n    -a, --arch                Override system architecture\n    -u, --unstable            Include unstable versions in list\n```\n\n## Uninstall\n\n`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.\n\nFirst of all, get some info about your system:\n\n```shell\necho $SHELL\necho $GOROOT\necho $GOPATH\ncommand -v g\n```\n\nYou 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 `g`:\n\n```shell\n# If you're using bash, zsh, or other POSIX shell:\nrm \"$(command -v g)\"\n\n# If you're using fish:\nrm (command -v g)\n```\n\nNow, if you want to remove everything, first **be sure to backup** your projects inside `$GOROOT`, if any. Then remove everything inside `$GOROOT` and `$GOPATH`:\n\n```shell\nrm -r $GOPATH $GOROOT\n```\n\nThen 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:\n\n```shell\n# bash on MacOS\n~/.bash_profile\n\n# bash on linux/BSD\n~/.bashrc\n\n# zsh\n~/.zshrc\n\n# fish shell\n~/.config/fish/config.fish\n\n# csh\n~/.cshrc\n\n# tcsh\n~/.tcshrc\n\n# For ash and dash, check your $ENV var\necho $ENV\n```\n\nAt this point you would have removed `g` and `go` entirely.\n\n## TODO\n\n- [x] Improve docs a bit more\n- [x] Make `g` and `g-install` POSIX compliant\n- [x] Add support for more shells\n- [x] Warn users they already have a golang installation when using `g-install`\n- [x] Use better naming for `g install \u003cversion\u003e`, maybe `use` or `set`. See #8\n  - [x] Use `install` only for install and remove the `--download` option\n- [x] Handle the case when `g` already exists, mainly `zsh` with `oh-my-zsh`\n  - [x] Make it so `g-install` offers the user to setup an alternative alias for `g`\n- [x] Make the `self-upgrade` command throw if `g` was not installed in the common way\n- [ ] Add a `complete` command that generates completions for the supported shells\n  - [ ] And have `g-install` setup the shells to call this command for completions\n- [ ] Explore feature to configure shells to autoload go versions based on mod.go\n- [x] Test it on diff platforms\n- [x] Crete a test setup with ~docker and~ Github actions\n- [ ] Add more tests\n\n## The alternatives (and why I prefer `g`)\n\n- [moovweb/gvm](https://github.com/moovweb/gvm)\n  - Too many features.\n  - Builds from source, i.e, requires gcc, make, xcode, etc.\n  - Requires git and mercurial.\n  - Requires bootstrapping, i.e., install go 1.4 first.\n  - Specific to a shell, i.e., doesn't work with fishshell.\n- [syndbg/goenv](https://github.com/syndbg/goenv)\n  - Too many features and weird DX.\n  - Uses an hard-coded list of go versions...\n  - ...thus you have to upgrade `goenv` before installing a new version of go.\n  - Adds a lot to your env and PATH.\n- [hit9/oo](https://github.com/hit9/oo)\n  - Pretty much same as `gvm`.\n- [asdf-golang](https://github.com/kennyp/asdf-golang)\n  - Depends on [asdf](https://github.com/asdf-vm/asdf).\n- [andrewkroh/gvm](https://github.com/andrewkroh/gvm)\n  - Bash, batch and powershell support only.\n  - Cumbersome to use.\n- [MakeNowJust/govm](https://github.com/MakeNowJust/govm)\n  - Builds from source.\n  - Requires python 2.\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](./CONTRIBUTING.md). ♥\n\n## Acknowledgments\n\n- [Every contributor to this project](https://github.com/stefanmaric/g/graphs/contributors).\n- The [`n` project](https://github.com/tj/n), which `g` is inspired by and based on.\n- The [`n-install` project](https://github.com/mklement0/n-install), which `g` is also based on.\n\n## License\n\n[MIT](./LICENSE) ♥\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanmaric%2Fg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanmaric%2Fg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanmaric%2Fg/lists"}