Skip to content

Instantly share code, notes, and snippets.

@Zate
Last active February 5, 2024 18:19
Show Gist options
  • Save Zate/b3c8e18cbb2bbac2976d79525d95f893 to your computer and use it in GitHub Desktop.
Save Zate/b3c8e18cbb2bbac2976d79525d95f893 to your computer and use it in GitHub Desktop.
Shell script to download and install latest golang
#! /bin/bash
# [get_golang.sh](https://gist.github.com/n8henrie/1043443463a4a511acf98aaa4f8f0f69)
# Download latest Golang release for AMD64
# https://dl.google.com/go/go1.10.linux-amd64.tar.gz
set -euf -o pipefail
# Install pre-reqs
sudo apt-get install python3 git -y
o=$(python3 -c $'import os\nprint(os.get_blocking(0))\nos.set_blocking(0, True)')
#Download Latest Go
GOURLREGEX='https://dl.google.com/go/go[0-9\.]+\.linux-amd64.tar.gz'
echo "Finding latest version of Go for AMD64..."
url="$(wget -qO- https://golang.org/dl/ | grep -oP 'https:\/\/dl\.google\.com\/go\/go([0-9\.]+)\.linux-amd64\.tar\.gz' | head -n 1 )"
latest="$(echo $url | grep -oP 'go[0-9\.]+' | grep -oP '[0-9\.]+' | head -c -2 )"
echo "Downloading latest Go for AMD64: ${latest}"
wget --quiet --continue --show-progress "${url}"
unset url
unset GOURLREGEX
# Remove Old Go
sudo rm -rf /usr/local/go
# Install new Go
sudo tar -C /usr/local -xzf go"${latest}".linux-amd64.tar.gz
echo "Create the skeleton for your local users go directory"
mkdir -p ~/go/{bin,pkg,src}
echo "Setting up GOPATH"
echo "export GOPATH=~/go" >> ~/.profile && source ~/.profile
echo "Setting PATH to include golang binaries"
echo "export PATH='$PATH':/usr/local/go/bin:$GOPATH/bin" >> ~/.profile && source ~/.profile
echo "Installing dep for dependency management"
go get -u github.com/golang/dep/cmd/dep
# Remove Download
rm go"${latest}".linux-amd64.tar.gz
# Print Go Version
/usr/local/go/bin/go version
python3 -c $'import os\nos.set_blocking(0, '$o')'
#! /bin/bash
set -euf -o pipefail
sudo apt-get install gpg -y
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt-get update -y
sudo apt-get install code-insiders -y
sudo apt-get install libxss1 libasound2 -y
code-insiders --install-extension lukehoban.Go
code-insiders --install-extension PeterJausovec.vscode-docker
code-insiders --install-extension Zignd.html-css-class-completion
code-insiders --install-extension ecmel.vscode-html-css
code-insiders --install-extension redhat.vscode-yaml
code-insiders --install-extension codezombiech.gitignore
code-insiders --install-extension IBM.output-colorizer
code-insiders --install-extension donjayamanne.git-extension-pack
code-insiders --install-extension formulahendry.docker-extension-pack
code-insiders --install-extension foxundermoon.shell-format
code-insiders --install-extension eamodio.gitlens
code-insiders --install-extension donjayamanne.githistory
code-insiders --install-extension Shan.code-settings-sync
code-insiders --install-extension Equinusocio.vsc-material-theme
code-insiders --install-extension yzhang.markdown-all-in-one
code-insiders --install-extension anseki.vscode-color
code-insiders --install-extension shd101wyy.markdown-preview-enhanced
code-insiders --install-extension PKief.material-icon-theme
code-insiders --install-extension robertohuertasm.vscode-icons
code-insiders --list-extensions --show-versions
@andygarfield
Copy link

andygarfield commented Jan 27, 2024

This is what I'm using:

GO_ARCHIVE=$(curl -s 'https://go.dev/VERSION?m=text' | head -n 1).linux-arm64.tar.gz
GO_LINK="https://go.dev/dl/$GO_ARCHIVE"
wget $GO_LINK
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf $GO_ARCHIVE
rm $GO_ARCHIVE

Just change the linux and arm64 to suit your needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment