Go on Raspberry Pi

Installing Go on Raspberry Pi is very simple. First, download and unpack the Go package

$ wget https://storage.googleapis.com/golang/go1.8.3.linux-armv6l.tar.gz
$ sudo tar -C /usr/local -xzf go1.8.3.linux-armv6l.tar.gz
$ export PATH=$PATH:/usr/local/go/bin

and then add export PATH=$PATH:/usr/local/go/bin to ~/.profile to set it automatically on next login.

To test whether it is working well, create test file server.go

package main

import (  
    "log"
    "net/http"
)

func main() {  
    http.Handle("/", http.FileServer(http.Dir(".")))

    log.Printf("Starting HTTP Web Server")
    log.Fatal(http.ListenAndServe(":80", nil))
}

build it and run

$ go build server.go
$ sudo ./server

Now if you open the http://your_raspberry_pi_ip_address/ the browser should list the content of the folder where the server.go is.

To run the server detached from terminal use

$ sudo nohup ./server </dev/null >server.log 2>&1 &

The server should be running even when you exit from the terminal.

To terminate the server fist find its PID

$ ps aux | grep server
...
root     22511  0.1  0.3 829024  3764 pts/0    Sl   01:01   0:00 ./server  
...

and the send kill signal to the process

$ sudo kill 22511

Alex Netkachov

Alex Netkachov is a Senior Software Developer, currently working in Central London on new generation of energy trading solutions for brokers, traders and exchanges.