Skip to content

Instantly share code, notes, and snippets.

@simoncos
Forked from konradko/golang_on_rpi.md
Last active March 30, 2024 17:56
Show Gist options
  • Star 82 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save simoncos/49463a8b781d63b5fb8a3b666e566bb5 to your computer and use it in GitHub Desktop.
Save simoncos/49463a8b781d63b5fb8a3b666e566bb5 to your computer and use it in GitHub Desktop.
Install Golang 1.9 on Raspberry Pi

Install Golang 1.9:

wget https://storage.googleapis.com/golang/go1.9.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.9.linux-armv6l.tar.gz
export PATH=$PATH:/usr/local/go/bin # put into ~/.profile

If already installed old golang with apt-get:

sudo apt remove golang
sudo apt-get autoremove
source .profile

Test:

go version
Copy link

ghost commented Dec 14, 2017

@simoncos Change sudo apt remove golang to sudo apt remove golang*. When I installed go v1.6 it installed it under golang-go and also installed some golang-1.6-* and golang-src packages

@heiko1234
Copy link

Ok, i have tried to install go (golang) but these short instructions do not help me.
May you can give me a simple short instruction what to write wehre. I guess i have to modifi .profile but how?!?
I get really confused because I only see wenn using "go env" : GOBIN = "", GOEXE="", GOPATH="", GOROOT="/home/pi/go" but i cannot change GOPATH.
So please be so kind and give some more information than only 3 single lines for some really studip or new raspberrypi people.
I try to learn but so far I miss a good explanation or skript from all the experts.

@leemcloughlin
Copy link

After running the wget and tar commands from @simoncos posting I add these two lines to the end of my ~/.bashrc, logout and then login again and go is then available

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin

@Oneiroi
Copy link

Oneiroi commented Mar 14, 2018

@leemcloughlin you need not logout and back in; you can simply run source ~/.bashrc after making modifications to load them into your current shell session

@Oneiroi
Copy link

Oneiroi commented Mar 14, 2018

To install golang 1.10 (or whatever the latest version is at the time anyone is reading this):

wget https://storage.googleapis.com/golang/go1.10.linux-armv6l.tar.gz
sudo tar -C /usr/local -xvf go1.10.linux-armv6l.tar.gz
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc

Run go version to check and you should see output of: go version g1.10 linux/arm also this preserves /usr/bin/go is you installed it previously.

@Sloaix
Copy link

Sloaix commented Apr 24, 2018

1.10.1 is released.

wget https://storage.googleapis.com/golang/go1.10.1.linux-armv6l.tar.gz
sudo tar -C /usr/local -xvf go1.10.1.linux-armv6l.tar.gz
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc

@meepiquitous
Copy link

To summarize (and learn md formatting):

1. Look up the most recent go version:

https://golang.org/dl/

ctrl+f armv6

Seems like 1.10.2 just came out!

2. Copy the download link:

https://dl.google.com/go/go1.10.2.linux-armv6l.tar.gz

3. Paste the following, line by line:

wget https://dl.google.com/go/go1.10.2.linux-armv6l.tar.gz

sudo tar -C /usr/local -xvf go1.10.2.linux-armv6l.tar.gz

cat >> ~/.bashrc << 'EOF'

export GOPATH=$HOME/go

export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin

EOF

source ~/.bashrc

go version


If wget fails with an error like this, your server time might be wrong:

ERROR: The certificate of ‘dl.google.com’ is not trusted.
ERROR: The certificate of ‘dl.google.com’ is not yet activated.
The certificate has not yet been activated.

To check your server time, enter

date

You can set the time manually:

date -s "17 MAY 2018 14:32:56"

If everything else fails, you can also give up and install go with Go Version Manager (gvm).

@nicochidt
Copy link

nicochidt commented Jun 13, 2018

This will work for the latest version (until google change the urls):

url=`curl https://golang.org/dl/ | grep armv6l | sort --version-sort | tail -1 | grep -o -E https://dl.google.com/go/go[0-9]+\.[0-9]+((\.[0-9]+)?).linux-armv6l.tar.gz` 
wget ${url}
sudo tar -C /usr/local -xvf `echo ${url} | cut -d '/' -f5`
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc

@alfonmga
Copy link

Thanks for sharing, it worked fine.

@angeldv
Copy link

angeldv commented Jan 29, 2019

Very useful.
Thanks¡

@emelendez89
Copy link

What's wrong with apt-get golang?

@nwandabridges
Copy link

I think apt-get golang installs 1.7 by default @emelendez89

@Markus2801A
Copy link

Markus2801A commented Aug 25, 2019

unfortunatly sudo apt-get install golang installs v1.11 but latest version is v1.12.9 since February 2019!
Don't know why they didn't update the package list für APT commands?!

@Kirbo
Copy link

Kirbo commented Mar 12, 2020

This will work for the latest version (until google change the urls):

url=`curl https://golang.org/dl/ | grep armv6l | sort --version-sort | tail -1 | grep -o -E https://dl.google.com/go/go[0-9]+\.[0-9]+((\.[0-9]+)?).linux-armv6l.tar.gz` 
wget ${url}
sudo tar -C /usr/local -xvf `echo ${url} | cut -d '/' -f5`
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc

Didn't work for me, so here's the fixed version that did work for me:

url=$(curl https://golang.org/dl/ | grep armv6l | sort --version-sort | tail -1 | grep -o -E "https://dl.google.com/go/go[0-9]+\.[0-9]+((\.[0-9]+)?).linux-armv6l.tar.gz")
archive_name=$(echo ${url} | cut -d '/' -f5)
wget ${url}
sudo tar -C /usr/local -xvf ${archive_name}
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
rm ${archive_name}
source ~/.bashrc

@gitroli1220
Copy link

A warm welcome!
I've tried to install go on my Raspberry4.
on executing "go version" I receive an: "cannot execute binary file: Exec format error"

Any ideas?

@movsb
Copy link

movsb commented May 25, 2020

@gitroli1220
Copy link

I sorted that out. The arm64 is the wrong version. v6l is appropriate!

@gitroli1220
Copy link

https://golang.org/dl/
https://dl.google.com/go/go1.13.4.linux-armv6l.tar.gz

@gitroli1220 Download this one.

Oh thanks, page reload world have helped me out earlier :)

@jt3k
Copy link

jt3k commented Sep 1, 2020

Current corrected version of the script

url='https://golang.org'$(curl https://golang.org/dl/ | grep armv6l | sort --version-sort | tail -1 | grep -o -E "/dl/go[0-9]+\.[0-9]+((\.[0-9]+)?).linux-armv6l.tar.gz")
archive_name=$(echo ${url} | cut -d '/' -f5)
wget ${url}
sudo tar -C /usr/local -xvf ${archive_name}
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
rm ${archive_name}
source ~/.bashrc

@rainthstrive
Copy link

Current corrected version of the script

url='https://golang.org'$(curl https://golang.org/dl/ | grep armv6l | sort --version-sort | tail -1 | grep -o -E "/dl/go[0-9]+\.[0-9]+((\.[0-9]+)?).linux-armv6l.tar.gz")
archive_name=$(echo ${url} | cut -d '/' -f5)
wget ${url}
sudo tar -C /usr/local -xvf ${archive_name}
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
rm ${archive_name}
source ~/.bashrc

Just did it on my Pi 4 and it worked perfectly. Thanks.

@guizzardi
Copy link

Current corrected version of the script

url='https://golang.org'$(curl https://golang.org/dl/ | grep armv6l | sort --version-sort | tail -1 | grep -o -E "/dl/go[0-9]+\.[0-9]+((\.[0-9]+)?).linux-armv6l.tar.gz")
archive_name=$(echo ${url} | cut -d '/' -f5)
wget ${url}
sudo tar -C /usr/local -xvf ${archive_name}
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
rm ${archive_name}
source ~/.bashrc

... works on Pi Zero too.

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