Last active
May 10, 2022 22:12
-
-
Save rustysys-dev/a6b74eeb16b3fb04cc0dc9a254139894 to your computer and use it in GitHub Desktop.
Update Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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