Skip to content

Instantly share code, notes, and snippets.

@Alldbg
Last active March 1, 2023 16:29
Show Gist options
  • Save Alldbg/39bdebe90df3688fc7d3db90e981e7f0 to your computer and use it in GitHub Desktop.
Save Alldbg/39bdebe90df3688fc7d3db90e981e7f0 to your computer and use it in GitHub Desktop.
# just execute this command: curl -fsSLo-curl -fsSLo- https://gist.githubusercontent.com/Alldbg/..To-This-Gist... | bash
# Thanks to "https://github.com/codenoid/install-latest-go-linux/blob/main/install-go.sh"
printf "Thanks to https://github.com/codenoid/install-latest-go-linux/blob/main/install-go.sh \n"
printf "Checking latest Go version...\n";
LATEST_GO_VERSION="$(curl --silent https://go.dev/VERSION?m=text)";
LATEST_GO_DOWNLOAD_URL="https://golang.org/dl/${LATEST_GO_VERSION}.linux-amd64.tar.gz "
printf "cd to home ($USER) directory \n"
cd "/home/$USER"
printf "Downloading ${LATEST_GO_DOWNLOAD_URL}\n\n";
curl -OJ -L --progress-bar https://golang.org/dl/${LATEST_GO_VERSION}.linux-amd64.tar.gz
printf "Extracting file...\n"
tar -xf ${LATEST_GO_VERSION}.linux-amd64.tar.gz
export GOROOT="/home/$USER/go"
export GOPATH="/home/$USER/go/packages"
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
printf '⚠️ ADD (OR REPLACE) THIS LINE BELOW TO YOUR ~/.bashrc ⚠️
export GOROOT="/home/$USER/go"
export GOPATH="/home/$USER/go/packages"
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
\n'
printf '⚠️ For root user ==> NOT EXECUTED IN THIS SCRIPT⚠️
export GOROOT="/root/go"
export GOPATH="/root/go/packages"
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
\n'
printf ' Done!
the ~/go is your $GOROOT folder.
I suggest you to start your project outside $GOROOT directory, idk, maybe ~/Document/project ?
To update Go on Linux machine
Delete existing $GOROOT directory (~/go?)
Install "New" Latest Go version with the command above :)
\n\n'
printf "You are ready to Go!\n";
go version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment