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).