Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Forked from random-robbie/install_go_pi.sh
Last active February 24, 2024 19:35
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save pcgeek86/0206d688e6760fe4504ba405024e887c to your computer and use it in GitHub Desktop.
Save pcgeek86/0206d688e6760fe4504ba405024e887c to your computer and use it in GitHub Desktop.
Install Go Lang on Raspberry Pi
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
@sighmon
Copy link

sighmon commented Oct 23, 2021

New download location for v1.17.2

cd $HOME
file='go1.17.2.linux-armv6l.tar.gz'
wget "https://golang.org/dl/$file"
sudo tar -C /usr/local -xvf "$file"
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc

@glowinthedark
Copy link

glowinthedark commented Feb 23, 2022

Modifications:

  • delete /usr/local/go if it exists
  • does NOT add the GOPATH if it's already there
  • optionally delete the downloaded archive (ctr+c to skip)
  • chained with && so that the script exits early on failure

forked gist (v1.20.5):

go 1.17.7

cd /tmp
fileName='go1.17.7.linux-armv6l.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"

go 1.20.5

cd /tmp
fileName='go1.20.5.linux-armv6l.tar.gz'
wget -c https://go.dev/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"

@sighmon
Copy link

sighmon commented Mar 21, 2022

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"

@glowinthedark
Copy link

glowinthedark commented Sep 4, 2023

Universal script for the LATEST golang version Raspberry (updated for Pi 5)

Uses the latest golang version endpoint

#!/usr/bin/env bash

read -p "Press any key to delete the previous golang installation (if present)..."
sudo rm -rfv "/usr/local/go"
mkdir -p $HOME/go

# detect if on a 32bit or 64bit OS
if [[ $(uname -m) == aarch64 ]]; then
    ARCH="arm64"
else
    ARCH="armv6l"
fi

cd /tmp

# see https://stackoverflow.com/a/46624091/191246
version=$(curl -s 'https://go.dev/VERSION?m=text' | head -n 1)

fileName="${version}.linux-${ARCH}.tar.gz"
read -p "Press any key to download and unpack $fileName... "
wget -c https://go.dev/dl/$fileName && sudo tar -C /usr/local -xvf $fileName

# add bash env vars if not already present
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