Installing Go Compiler On Raspberry Pi 4 (Raspberry Pi OS 32-Bit)

Go (Golang) requires a compiler to build it’s code and it only takes a few lines to install that compiler on the Raspberry Pi. I’m using a Raspberry Pi 4 with Raspberry Pi OS (32-bit).

Download the appropriate binary release

The binaries are available from https://golang.org/dl/ . The Raspberry Pi 4 is running on an ARMV7 chip and I’m running the 32-bit version of the OS, so the ARMV8 64bit is out of the question. I chose the go1.14.4.linux-armv6l.tar.gz download.

Extract The Tar File

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

Note: The file name will vary depending on what you have download, version number etc… so please make sure to update this.

Add Go To PATH

Instead of manually typing out the full path to the Go binary when its needed, it can be added to the accounts PATH environment using:

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

Note: Do not sudo this command.

Compile A Go File

To compile a .go file use the command:

go build filename.go

For example, if you had a file called geek.go containing:

package main

import "fmt"

func main() {
	fmt.Printf("geektechstuff.com\n")
}

Then:

go build geek.go

Will build it and:

./geek

Will then run the outputted file (which prints geektechstuff.com to screen).

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.