Skip to content

Instantly share code, notes, and snippets.

@rustysys-dev
Last active May 10, 2022 22:12
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 rustysys-dev/a6b74eeb16b3fb04cc0dc9a254139894 to your computer and use it in GitHub Desktop.
Save rustysys-dev/a6b74eeb16b3fb04cc0dc9a254139894 to your computer and use it in GitHub Desktop.
Update Golang
update_go() {
local LATEST
local GOBIN
local PATHRC
LATEST="$(curl -sL "https://golang.org/dl/?mode=json" | jq -r .[0].version)"
GOBIN='${HOME}/go/bin'
PATHRC="${HOME}/.bashrc.d/pathrc"
curl -sLo go.tar.gz "https://dl.google.com/go/$LATEST.linux-amd64.tar.gz"
rm -rf "${HOME}/go"
tar -C "${HOME}" -xzf go.tar.gz
rm -f go.tar.gz
if grep -q GOBIN "$PATHRC"; then
sed -i "s|^export GOBIN=.*$|export GOBIN=$GOBIN|" $PATHRC
else
sed -i "s|^export PATH=\(.*$\)|export GOBIN=$GOBIN\nexport PATH=\${GOBIN}:\1|" $PATHRC
fi
. "${HOME}/.bashrc"
go version
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment