Skip to content

Instantly share code, notes, and snippets.

@mangalaman93
Last active November 2, 2015 04:30
Show Gist options
  • Save mangalaman93/ab970fdcbc778ae16100 to your computer and use it in GitHub Desktop.
Save mangalaman93/ab970fdcbc778ae16100 to your computer and use it in GitHub Desktop.
virtual enviornment for golang
#!/bin/bash
if [[ $0 != "/bin/bash" ]]; then
echo "Error: source the script!"
exit 1
fi
if [[ ! -d $(pwd)/go/bin ]]; then
echo "Error: go installtion not found in the current directory!"
return
fi
if [[ -f ./deactivate ]]; then
echo "Error: already in a vritual enviornment!"
echo "delete ./deactivate and run again if you are sure!"
return
fi
# assuming
GOROOT=$(pwd)/go/bin
# delete old deactivate file
rm -f deactivate
# set custom PATH
OLD_PATH=$PATH
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$GOROOT
# modify GOPATH
OLD_GOPATH=$GOPATH
export GOPATH=$(pwd)
mkdir -p $GOPATH/src $GOPATH/bin $GOPATH/pkg
echo "export PATH=$OLD_PATH
export GOPATH=$OLD_GOPATH
rm $(pwd)/deactivate" > deactivate
chmod +x deactivate
echo "run \". $(pwd)/deactivate\" to go back to original enviornment"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment