Install go (golang) on Raspbian

golang raspberry pi
golang 1.9 raspberry pi
golang download
install go mac
install go tools
gopath raspberry pi
install go cli
go for raspberry pi 4

I checked diverse forums but I still did not make it working. I like to install go (golang) on my Raspberry PI - Raspbian:


sudo apt-get install golang

I installed go and with

export GOPATH=$home/pi/gocode

i set the GOPATH so i tryed to install from a homepage a new program with (sudo go get -u but, I only get "cannot download, $GOPATH not set. For more details see: go help gopath".

I really get crazy for my studip simple mistake that i do not see.

I would be pleased if i get a very detailed "how to do" discription since I am new to Linux and Raspbian, so everything which is made for real dummys should be good enough for me. Thank you for your help.

This are detailed instructions about how to install Go on Raspbian Stretch from the repositories.

As of today, 2018-01-30, this will install Go 1.7. The most actual version for manual installation from the downloads is Go 1.9.3.

I. Login to your user on the Raspberry Pi (I'm using the default user pi).

II. Install Go (golang)

pi@pi3-2:~ $ sudo apt update 
pi@pi3-2:~ $ sudo apt install golang

III. Create a working directory for all your go projects in your $HOME directory. It's best to name it go, as this defaults to the GOPATH in future Go versions (starting with Go 1.8).

pi@pi3-2:~ $ mkdir go

IV. Append the $GOPATH environment variable and modified PATH settings to your .profile

pi@pi3-2:~ $ echo 'export GOPATH=$HOME/go' >> ~/.profile
pi@pi3-2:~ $ echo 'PATH="$HOME/go/bin:$PATH"' >> ~/.profile

V. Logout and Relog with the new settings then check your settings

pi@pi3-2:~ $ go env

GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build187598155=/tmp/go-build -gno-record-gcc-switches"

Especially make sure GOPATH points to your previously created Go working directory. Don't care about setting GOBIN as mentioned in some documentation. It's usually not necessary and Go will automatically use $GOPATH/bin/ for your Go installs.

However, you might also want to check the path settings (/home/pi/go/bin should be included) to make sure you can run the code you installed with go install.

pi@pi3-2:~ $ echo $PATH

VI. A few words about the Go working directory structure

Over time, the Go working directory will contain three sub-directories: bin, src and pkg. Except src they will be automatically created, when needed the first time. The structure for user pi will look like this:


bin will contain all Go executable's you have installed using go install command.

pkg will contain all compiled packages that can be imported into your projects.

src will contain all your source files, either your own or sources downloaded from external repositories.

For eksample the command go get will automatically fetch and place the source files from the corresponding external Github repository into the local directory $HOME/go/src/

As it's rather common to fetch external repositories either for reference or contribution it becomes important to keep your directory structure always well organized and clean.

Apart from that you are free to organize your projects as long they are hierarchically structured below the $HOME/go/src/ directory and follow the rules mentioned in the documentation.

However, to clearly organize my projects I personally always place my projects into $HOME/go/src/ even if I don't have an external repository for it.

If you don't have a github account you can likewise use any other external repository account.

As I mentioned, even it's not needed at all I prefere to use my Github account to clearly identify my projects. And even it's not needed I will use the username pi to distinct the user from other project maintainers in the following example.

VII. So let's add a "hello world" project to test our installation.

a) First let's create the project folder and cd into its directory.

pi@pi3-2:~ $ mkdir -p $HOME/go/src/pi/helloworld
pi@pi3-2:~ $ cd $HOME/go/src/pi/helloworld
pi@pi3-2:~/go/src/pi/helloworld $

b) With an editor of your choice create a file main.go with the following content

// helloworld project main.go.
package main

import ("fmt")

// main is the entrypoint of the application.
func main() {
  fmt.Println("Hello world! Greetings from Raspberry Pi")

Spacing doesn't matter at this point. Go provides a nice tool to do this for you.

c) Now try to run the program.

pi@pi3-2:~/go/src/pi/helloworld $ go run main.go
Hello world! Greetings from Raspberry Pi
pi@pi3-2:~/go/src/pi/helloworld $

In case you get an error, fix it! Carefully, check the spelling and cases (Go is case-sensitive).

d) Next lets format the code:

pi@pi3-2:~/go/src/pi/helloworld $ go fmt

Without a file name this will properly (re-)format all source files within this directory and below.

e) Next let's build helloworld as an executable procram, within this directory.

pi@pi3-2:~/go/src/pi/helloworld $ go build
pi@pi3-2:~/go/src/pi/helloworld $ ls
helloworld  main.go
pi@pi3-2:~/go/src/pi/helloworld $

f) Now you can run it.

pi@pi3-2:~/go/src/pi/helloworld $ ./helloworld
Hello world! Greetings from Raspberry Pi
pi@pi3-2:~/go/src/pi/helloworld $

g) Finally let's install the program into the $HOME/go/bin/ directory.

pi@pi3-2:~/go/src/pi/helloworld $ go install
pi@pi3-2:~/go/src/pi/helloworld $ ls $HOME/go/bin
hello-go  helloworld
pi@pi3-2:~/go/src/pi/helloworld $

h) If everything is done right it can be run by our pi user from anywhere by just entering the name of the command.

pi@pi3-2:~/go/src/pi/helloworld $ helloworld
Hello world! Greetings from Raspberry Pi
pi@pi3-2:~/go/src/pi/helloworld $ cd ~
pi@pi3-2:~ $ helloworld
Hello world! Greetings from Raspberry Pi
pi@pi3-2:~ $


Install go (golang) on Raspbian, I recently want to install Golang(Go) on my Raspberry Pi, and realised that the easy way to install Golang may not be the better way to install� If you search “Golang Raspberry Pi”, you are likely come across this link “Install Golang the easy way” on Raspberry Pi Stack Exchange. Golang is included in Debian (and therefore Raspbian) linux distribution, so the easy way to install Golang is using the simple and familiar linux command: sudo apt-get install golang

as of Nov 2019. (Please note if you need version 1.13+ please wget go1.13.3.linux-amd64.tar.gz manually) OR sudo apt-get install golang-go - source

You just have to type following commands on your RPi

sudo apt-get update
sudo apt-get install golang --fix-missing

and when you type now go version following should be your output

pi@rpi1:~ $ go version
go version go1.11.6 linux/arm

Additionally, I also had the following installed before running everything sudo apt-get install make gcc g++

A Better way to install Golang (Go) on Raspberry Pi – E-Tinkers, If already installed old golang with apt-get: sudo apt remove Ok, i have tried to install go (golang) but these short instructions do not help me. May you can give� Just as old saying "all roads lead to Rome", many ways can be used to install Go (Golang) on Raspbian Stretch (Debian 9). However, I'll just mention two methods here: Install from official Debian repository (version 1.7 by the time of this writing)

How to install golang:

Download the latest tarball, go1.9.linux-armv6l.tar.gz, to a directory such as /home/pi/downloads.

Then use:

sudo tar -C /home/pi -xzf go1.9.linux-armv6l.tar.gz

to extract the go installation to the directory


creating /home/pi/go

to check use

go version

Which will give you the actual version of go.

It should be go1.9 linux/arm.

Please check with:

go env


go env GOPATH

the GOPATH direction


ls -a # (used in /home/pi/ )

give you a list of all files and also shows you ~/.profile


sudo nano ~/.profile

you can open that file an add the reccommended code for the go directory

 export GOROOT=/home/pi/go
 export GOPATH=/home/pi/go/bin

close with STRG + O and ENTER and STRG + X

check with

go env GOPATH

then use

source ~/.profile

then you can check again with

go env

Now go should be running on the latest version and should have the correct GOPATH directory

For me helpful was this link:

I really hope some others also give detailed descriptions of how to install a program in a brief and detailed way. Instead of 3 lines of single code.

Install Golang 1.9 on Raspberry Pi � GitHub, Installation Methods. Just as old saying "all roads lead to Rome", many ways can be used to install Go (Golang) on Raspbian Stretch (Debian� Download the Go distribution. Download Go Click here to visit the downloads page. Official binary distributions are available for the FreeBSD (release 10-STABLE and above), Linux, macOS (10.11 and above), and Windows operating systems and the 32-bit (386) and 64-bit (amd64) x86 processor architectures.

How to Install Go (Golang) on Raspberry Pi 3 (Raspbian Stretch , The Raspberry Pi has captured the imagination of hackers and makers alike. This post describes the steps for installing Google Go from source on the install the following packages, described on the website. There's already a go compiler in, e.g., raspbian, which you can find with apt-cache search golang. This looks to be version 1.0.2. This looks to be version 1.0.2. The site you linked has pre-compiled tarballs of 1.3.3 available for the pi.

Installing Go on the Raspberry Pi, Greetings: I have just started using a Raspberry Pi 4, 4gb. I tried installing the Golang software on it and when I try to execute "go version" or� This post if about installing the GO programming language. Follow the Raspberry Pi 3 first remote startup for simple Raspberry PI setup. Install using apt-get. To install the Raspberry PI version using apt-get run the following command line: pi@raspberrypi:~ $ sudo apt-get install golang. Note: this will take a few minutes to install.

Raspberry Pi 4 and Golang, If you want to install Go on your Raspberry Pi you have a few options. In the past there was a lot of cross compiling and hacking to get it done,� Raspbian comes with almost all the tools you need to compile Go already installed, but to be sure you should install the following packages, described on the website. % sudo apt-get install -y mercurial gcc libc6-dev

  • Never build using sudo. just use go get, go build, go install, etc.
  • As @JimB said don't use sudo to run the go command. You just need it to install it and your already did it with sudo apt-get. Just to let you know, you have set the GOPATH to your user when doing that export. But when you run somethin with sudo you are running a command as the root user which has not set the GOPATH. sudo -> "Do as super user"
  • Also, of you're getting a $GOPATH not set error, you're using an old version of Go. You may want to use the binary install directly from if it's available for your os/arch.
  • How to make go working: download the latest version of go in a new folder (like download) go1.9.linux-armv6l.tar.gz in a new directory like download install with sudo apt-get install golang an older version of go (golang) in my case it was 1.7.4 then use sudo tar -C /home/pi -xzf go1.9.linux-armv6l.tar.gz
  • to install go version 1.9 in a new directory in my case home/pi/go with sudo apt remove golang and sudo apt-get autoremove remove the older version of go to check unse go version which give you the actual version of go it should be go1.9 linux/arm please check with go env or go env GOPATH the GOPATH direction
  • Thank you @Peter. I've followed your well-written steps and everything works! this should be the accepted answer.
  • as awesome as the instructions are, and their great for testing out a new install of the go lang tooling, putting that helloworld directory within the $HOME/go/src directory will prevent packages from updating using go get -u [] the go get cmd will complain about having a directory within the src dir that hasn't been initialized with a VCS. see this
  • ok, one more comment on that export GOPATH =/home/pi/go export PATH=$PATH:/home/pi/go/bin in the ~/.profile document otherwise i got an error wenn trying to run go but now it works perfectly, no errors or anything even with the older version 1.7.4 of golang. so i really hope this helps others or me later on, when setting up again