Skip to content

Instantly share code, notes, and snippets.

@tcd1558
Last active August 31, 2021 21:27
Show Gist options
  • Save tcd1558/e9023590f9cf91fd185214f4b8c29d30 to your computer and use it in GitHub Desktop.
Save tcd1558/e9023590f9cf91fd185214f4b8c29d30 to your computer and use it in GitHub Desktop.
Installing Go on Raspberry OS

Installing Go on Raspberry OS

0. Overview

This document describes how to install Go in Raspberry OS

1. Contents

0. Overview
1. Contents
2. Syntax
3. Update the package repository
4. Upgrade the installed packages
5. Check what is available
6. Installing using apt
7. Installing using the download page
99. References

2. Syntax

[button] - is a button on the screen with the text 'button' on it.   
InputField: - is a field labeled 'InputField:', where you can enter text.   
<PlaceHolder> - a placeholder to be replaced with your own text (without the '<' and '>').  
[v] Label1 - ensure there is a check mark in front of the label 'Label1'
[x] Label2 - ensure there is an 'x' in the check box in front of the label 'Label2'
1/3 - step 1 of in total 3 steps
$ - prompt for a regular user
# - prompt for the root user (system administrator)
host $ - prompt for the regular user on the host system
host # - prompt for the root user on the host system 
container $ - prompt for the regular user in the container
container # - prompt for the root user in the container

3. Update the package repository database

$ sudo apt update

4. Upgrade the installed packages

$ sudo apt upgrade

5. Check what is available

$ apt policy golang

golang:
Installed: (none)
Candidate: 2:1.11~1+b6
Version table:
2:1.11~1+b6 500
500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages

If the target release has not been specified then APT simply assigns priority 100 to all installed package versions and priority 500 to all uninstalled package versions.

For more information:

$ man apt_preferences

In contrast to the golang page:
https://golang.org/dl/ Current version here is go.1.17.src.tar.gz

6. Installing using apt

$ sudo apt install golang

pi@raspberrypi: $ apt policy golang
golang:
Installed: 2:1.11~1+b6
Candidate: 2:1.11~1+b6
Version table:
*** 2:1.11~1+b6 500
500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
100 /var/lib/dpkg/status
pi@raspberrypi: $ go version
go version go1.11.6 linux/arm
pi@raspberrypi: $

7. Installing using the download page

You might have noticed, that the go package available through apt is not as up to date as the one available under:

https://golang.org/dl/

A Raspberry Pi is build around an ARM CPU. So when looking for the latest Go version, you should look for packages ending in:

..armv*.tar.gz

To see what type of ARM processor your Raspberry Pi is using, use the following command:

$ uname -m

At the time of writing this document, the Raspberry Pi system shows a machine name of:

armv7l

Furthermore, the latest release of go is version 1.17. Create a directory and download the latest version to that directory:

$ mkdir -p Go/src $ cd Go/src $ wget https://dl.google.com/go/ Replace >my-package> with the version you want to download. E.g. go1.17.linux-armv6l.tar.gz

Extract the tar-ball with:

sudo tar -C /usr/local -xzf go1.17.linux-armv6l.tar.gz

Add Go to your path and set the GOPATH variable, by editing your ~/.profile and adding the following line:

> if [ -d "/usr/local/go/bin" ] ; then    
>    PATH=$PATH:/usr/local/go/bin    
>    GOPATH=$HOME/go    
> fi    

The GOPATH variable is used to find the go programs you have created.

99. References:

https://www.jeremymorgan.com/tutorials/raspberry-pi/install-go-raspberry-pi/

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