Install Go Lang on Raspberry Pi
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
cd $HOME | |
FileName='go1.13.4.linux-armv6l.tar.gz' | |
wget https://dl.google.com/go/$FileName | |
sudo tar -C /usr/local -xvf $FileName | |
cat >> ~/.bashrc << 'EOF' | |
export GOPATH=$HOME/go | |
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin | |
EOF | |
source ~/.bashrc |
Version 1.18
for Raspberry Pi 4
cd /tmp
fileName='go1.18.linux-arm64.tar.gz'
wget -c https://golang.org/dl/$fileName && sudo rm -rfv /usr/local/go && sudo tar -C /usr/local -xvf $fileName
grep -q 'GOPATH=' ~/.bashrc || cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc
read -p "Press any key to delete downloaded file: $fileName..."
rm -rf "$fileName"
Universal script for the LATEST golang version
Uses the latest golang version endpoint
read -p "Press any key to delete the previous golang installation (if present)..."
rm -rf "/usr/local/go"
mkdir -p $HOME/go
cd /tmp
# see https://stackoverflow.com/a/46624091/191246
version=$(curl -s 'https://go.dev/VERSION?m=text' | head -n 1)
fileName="${version}.linux-armv6l.tar.gz"
wget -c https://go.dev/dl/$fileName && sudo rm -rfv /usr/local/go && sudo tar -C /usr/local -xvf $fileName
# add bash env vars if not already there
grep -q 'GOPATH=' ~/.bashrc || cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc
read -p "Press any key to delete downloaded file: $fileName..."
rm -rf "$fileName"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modifications:
/usr/local/go
if it existsGOPATH
if it's already there&&
so that the script exits early on failureforked gist (v1.20.5):
go 1.17.7
go 1.20.5