Skip to content

Instantly share code, notes, and snippets.

@sleaze
Forked from jpillora/install-go.sh
Last active May 23, 2020 18:28
Show Gist options
  • Save sleaze/5c283c2d99f02be081f2567747742531 to your computer and use it in GitHub Desktop.
Save sleaze/5c283c2d99f02be081f2567747742531 to your computer and use it in GitHub Desktop.
Install latest version of Go in Linux
#!/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
export INSTALL_GO_SH="$0"
main() {
if [[ "${1:-}" =~ ^(-v|--verbose)$ ]]; then
set -o errexit
fi
# Force run with bash.
if [ -z "${BASH_VERSION:-}" ]; then
exec /bin/bash "${INSTALL_GO_SH}" "$@"
exit
fi
local VER
local ARCH
local FILE
echo "INFO: Fetching latest Go version ..." 1>&2
typeset VER="$(curl -s 'https://golang.org/dl/' | grep -m 1 -o 'go1\.[0-9.]\+')"
echo "INFO: Found latest version='${VER}'" 1>&2
if uname -m | grep -q 64; then
typeset ARCH=amd64
else
typeset ARCH=386
fi
typeset FILE="${VER}.linux-${ARCH}"
echo "INFO: Installing '${FILE}' ..." 1>&2
curl -# https://storage.googleapis.com/golang/$FILE.tar.gz \
| tar -C /usr/local -xzf -
if ! grep -q '^# Go Paths .*$' "${HOME}/.bashrc"; then
echo "
# Go Paths (Added on: $(date -u))
export GOPATH=\"\${HOME}/go\"
export PATH=\"\${PATH}:/usr/local/go/bin:\${GOPATH}/bin\"" >> ~/.bashrc
fi
. ~/.bashrc
echo "INFO: Go is installed and your GOPATH is '$HOME/go'" 1>&2
echo "INFO: Please reload this shell or enter the command '. ~/.bash_profile'" 1>&2
}
if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment