Go on the Raspberry Pi, How to setup the lastest version

Go en Raspberry Pi

How to setup the default GO language version of the Raspberry Pi with the APT INSTALL command

Setup the Go languague on the raspberry Pi is usually something very easy to do when we are using the apt package manager of the Raspberry Pi. We just need to execute:

sudo apt update
sudo apt install golang

However, the default version of Golang for the Raspberry Pi is not the last version of GoLang. And by this we will to unistall this version in case we had installed it and we are going to setup the last version from the official website.

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

How to setup the last version of Go language from him source code

Once we have use the above commands and therefore we have deleted the Golang version loaded with the APT package manager. Now we will download and setup the last version of Go language from the golang official website.

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

With the previous sequence of commands we have installed the most recent version of the Golang language from the official website. And in the same sequence of commands we have setup our GOPATH environment variable.

Now we are going to test that golang commands are working correctly running it in our terminal: go version

Testing go language in the Raspberry with the “Hello World”.

Finally we are going to build the “Hello World” program on Golang with the last version of this running over our nmachine. And for this case we will create the helloworld.go file with this code inside him:

package main

import (
 "log"
)

func main() {
 log.Printf("¡Hola Mundo!")
}

We will compile and run our golang “hello world” program.

go build helloword.go
./helloworld

With this we can now start to develop with the go language and the Raspbery Pi. If we want to develop a IoT app using the GPIO of the Rasperry pi with the Go language we have a really good library for this purposes Gobot that makes the interaction with the Raspberry Pi GPIO quite easy.

In my case i will develop an App in kiosk mode using the library go-astilectron this library allow us to integrate a web interface within our Golang App. So i will to proceed to download it for my environment.

go get -u github.com/asticode/go-astilectron

This guide has been tested with Raspbian Buster with Desktop and the Raspbian Buster Lite.

While i am writing this Post the last version of GO is the 1.14.2. We have to go to the official Golang website https://golang.org/dl/ to download the last version.

Clic aquí para visualizar está entrada en su versión en español.

Share: