Skip to content

Instantly share code, notes, and snippets.

@wshearn
Last active December 6, 2019 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wshearn/74cb727ccfcb44e59889d63db2551abc to your computer and use it in GitHub Desktop.
Save wshearn/74cb727ccfcb44e59889d63db2551abc to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
usage()
{
echo "GVM is a simple golang version manager written in bash."
echo "$(basename $0) -v <version>"
}
while getopts ":v:h" opt; do
case ${opt} in
h)
usage
exit 0
;;
v)
WANTED=${OPTARG}
;;
esac
done
if [[ -z ${WANTED} ]]; then
usage
exit 1
fi
if [[ ! -d ${HOME}/sdk/go${WANTED} ]]; then
echo "Runtime not found. Installing..."
go get golang.org/dl/go${WANTED}
go${WANTED} download
fi
pushd ${HOME}/sdk > /dev/null
rm -f active
ln -s go${WANTED} active
popd > /dev/null
if [[ ${PATH} != *"${HOME}/sdk/active/bin"* ]]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Runtime set, add it to your path"
echo "export PATH=\${PATH}:\${HOME}/sdk/active/bin"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
fi
@wshearn
Copy link
Author

wshearn commented Jun 17, 2019

Simple usage:

[0]Pluto:~ $ go version
go version go1.12.6 linux/amd64
[0]Pluto:~ $ gvm -v 1.12.5
Runtime not found. Installing...
Downloaded   0.0% (    15173 / 127938445 bytes) ...
Downloaded  27.7% ( 35389440 / 127938445 bytes) ...
Downloaded  83.4% (106659840 / 127938445 bytes) ...
Downloaded 100.0% (127938445 / 127938445 bytes)
Unpacking /home/whearn/sdk/go1.12.5/go1.12.5.linux-amd64.tar.gz ...
Success. You may now run 'go1.12.5'
[0]Pluto:~ $ go version
go version go1.12.5 linux/amd64
[0]Pluto:~ $ gvm -v 1.12.6
[0]Pluto:~ $ go version
go version go1.12.6 linux/amd64
[0]Pluto:~ $ 

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