Skip to content

Instantly share code, notes, and snippets.

@nicolas-grekas
Last active January 9, 2016 11:02
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 nicolas-grekas/a1d3058a95a65975e168 to your computer and use it in GitHub Desktop.
Save nicolas-grekas/a1d3058a95a65975e168 to your computer and use it in GitHub Desktop.
source ~/go/setup x.y.z
#!/bin/bash
go_version=$1
go_arch=linux-amd64
export GOPATH="$HOME/go"
if [ ! -e $GOPATH ]
then
mkdir $GOPATH
fi
if [ -e $GOPATH/current ]
then
cur_version=`cat $GOPATH/current`
if [[ "x" == "x$go_version" ]]
then
go_version=$cur_version
fi
export PATH=${PATH//:$GOPATH\/$cur_version\/bin:$GOPATH\/bin/}
fi
if [[ "x" == "x$go_version" ]]
then
echo 'Please specify the go version you want'
return
fi
if [ ! -e $GOPATH/$go_version.tar.gz ]
then
wget https://storage.googleapis.com/golang/go$go_version.$go_arch.tar.gz -O $GOPATH/$go_version.tar.gz
if [ ! $? ]
then
rm $GOPATH/$go_version.tar.gz
return
fi
tar -C $GOPATH -xzf $GOPATH/$go_version.tar.gz
if [ ! -e $GOPATH/$go_version ]
then
rm -Rf $GOPATH/$go_version
fi
mv $GOPATH/go $GOPATH/$go_version
fi
export GOROOT="$GOPATH/$go_version"
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
if [[ "$go_version" != "$cur_version" ]]
then
rm -Rf $GOPATH/pkg
echo $go_version > $GOPATH/current
fi
go version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment