Install and Configure Go/Golang on Raspberry Pi

Go/Golang is one of the hot programming languages while I’m typing this today.

Go is a programming language created at Google in 2009 by Robert Griesemer, Rob Pike and Ken Thompson. Go is a statically typed compiled, procedural language similar to C, with memory safety, garbage collection, structural typing, concurrency and other great features are bundled to make it better compared to other languages in the marketplace.

Docker, Kubernetes, Graphana, Hugo are some of the best apps written in Go. It has a robust set of libraries and app performance is better compared to other languages.

Today I’m starting my journey to learn Go/Golang and Google will be my mentor to install and setup Golang on my Raspbian OS/Raspberry Pi 3. To get the latest version use below steps instead of native package management tool such as apt.

Installation Steps:

  • Download the current stable version of Go available on the google’s official website. At the time of writing this tutorial, 1.12.4 is the stable version. Check the latest version here
cd ~ && curl -O https://dl.google.com/go/go1.12.4.linux-armv6l.tar.gz

Above command would change directory to your ‘Home’ directory and download Go compressed tar file using ‘Curl’

  • Extract compressed tar file and place it inside /usr/local directory. Please note root level access or sudo access required to perform this step.
sudo tar -C /usr/local -xzvf go1.12.4.linux-armv6l.tar.gz
  • Set Path variables to avoid typing complete path and in order to access binaries or libraries of Go by the Raspbian OS. Open ~/.profile, a hidden file located in your ‘Home’ directory. Use nano or vi or subl to edit the file (subl ~/.profile). Add below lines at the end of the file.
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
  • To take effect of the above changes made to the file ‘profile’, run the below command. The source command can be used to load any functions file into the current shell, script or a command prompt.
source ~/.profile
  • Create directory called ‘go’ in the ‘Home’ directory. All my codes are placed in the folder. Change the directory name as per choice but do change the GOPATH accordingly as mentioned above.
 mkdir $HOME/go 
  • Validate Go is working as expected or not by running below command
vb@pi:~ $  go version
go version go1.12.4 linux/arm
vb@pi:~ $

My first code in Go

Create a directory first_code in ‘go’ and write following content in the file and save it as first_code.go

mkdir -p $HOME/go/src/first_code 
{-p is used to create directory and its sub-directories at once}
package main

import "fmt"

func main() {
    fmt.Printf("My first code in Go Language!!!\n")
}

Now build and run the code. Change directory
to the first_code cd ~/go/src/first_code and run below commands

vb@pi:~/go/src/first_code $ go build
vb@pi:~/go/src/first_code $

vb@pi:~/go/src/first_code $ ./first_code
My first code in Go Language!!!
vb@pi:~/go/src/first_code $

Note:

Above steps are applicable to any Linux distributions just by changing the first step of downloading the compressed tar file. Change the architecture from arm6l to amd64 or as applicable to your hardware.

I am able to successfully setup GO on my Pi. Hope you’d also do the same and happy learning Go. If you have any issues or questions please mention them in the below comment section.

Advertisements

Manage services from CLI on Linux

In Window$ OS, we can check running services and its status by going to Services console. (Start > Run > services.exe)

Similarly, to access running services info and status under Linux via BASH / Shell, we need to install ‘sysv-rc-conf’

aptitude install sysv-rc-conf

Below screenshot show the output of sysv-rc-conf command displaying status of service for all running levels (1-6) and startup (S)

2016-11-21 11_06_38-Debian1 [Running] - Oracle VM VirtualBox.png

As you can see in the screenshot to start a service use ‘+’ and to stop a service use ‘-‘. To enable or disable service to run at startup goto the respective service’s ‘S’ column and then use ‘Space Bar’.

How to quickly setup Squid Proxy?

Squid proxy is one of the best open source proxy software’s and most widely implemented solutions. I was trying to quickly set this up with less efforts but with no compromise w.r.t implementing robust ACLs (Access Control Lists).

Instead of reading various Howto’s in the net, I started searching for ready made appliance which could make things easy for me 🙂

logo

After reviewing various options, I have had decided to go with Artica Proxy. Its pretty simple and its intuitive interface makes it simple to swiftly setup Squid Proxy within few minutes.

It offers Transparent Proxy, Load Balancer, 1.6 Millions blacklisted sites (updated on daily basis), user defined ACLs etc… For a full featured characteristics and benefits please visit the URI here.

I hope you’ll find this intelligent software useful and happy proxying!!

 

Create Debian bootable USBdrive

Downloaded latest version of Debian/Ubuntu in ISO format but don’t have CD/DVD to burn it.

Simple workaround… Use the most valuable DD command

dd if=/home/rambo/Downloads/debian.iso of=/dev/sdc

/home/rambo/Downloads/debian.iso [Replace this with your path to the downloaded iso file]

/dev/sdc [Replace ‘sdc’ with actual mounted USB device; use ‘mount’ command to identify the device]

NOTE: Please take backup of your USB Drive before running the above command