Skip to content

Instantly share code, notes, and snippets.

@neonxp
Last active July 13, 2022 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neonxp/b67684eac7a68455f098bb593ad01265 to your computer and use it in GitHub Desktop.
Save neonxp/b67684eac7a68455f098bb593ad01265 to your computer and use it in GitHub Desktop.
Simple version manager for golang
#!/bin/sh
if [ ! -f $HOME/go/bin/go$1 ]; then
echo "Version $1 not found, trying to install"
go install golang.org/dl/go$1\@latest
go$1 download
fi
rm $HOME/go/bin/go || true
echo "Linking go to version $1"
ln -s $HOME/go/bin/go$1 $HOME/go/bin/go
@neonxp
Copy link
Author

neonxp commented Dec 23, 2021

Usage:

Just run gv with version tag:

~ gv 1.17.5

Script will check if specified version not installed - gv will download it.

Next creates symlink to new version.

❯ gv 1.17.6                                                                                                           ~
Version 1.17.6 not found, trying to install
go: downloading golang.org/dl v0.0.0-20220106205509-1eec60721618
Downloaded   0.0% (    16384 / 136792188 bytes) ...
Downloaded   4.6% (  6356944 / 136792188 bytes) ...
Downloaded   9.5% ( 13057952 / 136792188 bytes) ...
Downloaded  15.9% ( 21692256 / 136792188 bytes) ...
Downloaded  23.6% ( 32292624 / 136792188 bytes) ...
Downloaded  30.4% ( 41549520 / 136792188 bytes) ...
Downloaded  35.9% ( 49086096 / 136792188 bytes) ...
Downloaded  42.6% ( 58277456 / 136792188 bytes) ...
Downloaded  49.4% ( 67599872 / 136792188 bytes) ...
Downloaded  55.8% ( 76381632 / 136792188 bytes) ...
Downloaded  62.7% ( 85785984 / 136792188 bytes) ...
Downloaded  69.0% ( 94453040 / 136792188 bytes) ...
Downloaded  75.8% (103693552 / 136792188 bytes) ...
Downloaded  83.3% (114015392 / 136792188 bytes) ...
Downloaded  90.7% (124025936 / 136792188 bytes) ...
Downloaded  98.3% (134495232 / 136792188 bytes) ...
Downloaded 100.0% (136792188 / 136792188 bytes)
Unpacking /Users/neonxp/sdk/go1.17.6/go1.17.6.darwin-amd64.tar.gz ...
Success. You may now run 'go1.17.6'
Linking go to version 1.17.6
❯ go version                                                                                                          ~
go version go1.17.6 darwin/amd64

Thats all!

@neonxp
Copy link
Author

neonxp commented Jul 13, 2022

gvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment