Skip to content

Instantly share code, notes, and snippets.

@conoro
Created April 23, 2016 16:24
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save conoro/4fca191fad018b6e47922a21fab499ca to your computer and use it in GitHub Desktop.
Save conoro/4fca191fad018b6e47922a21fab499ca to your computer and use it in GitHub Desktop.
Cross-compiling Golang for ARM64 (aarch64) e.g. Pine64 on Fedora AMD64
  • Install Go for Linux the usual way on your main Linux box:
cd
wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
tar -zxvf go1.6.2.linux-amd64.tar.gz
sudo mv go /usr/local/
export GOROOT=/usr/local/go
mkdir -p ~/gitwork/go/src
mkdir ~/gitwork/go/bin
mkdir ~/gitwork/go/pkg
export GOPATH=~/gitwork/go
go version
  • Cross-compile Go for ARM64
mkdir gobuild
cd gobuild/
git clone https://go.googlesource.com/go
cd go
git checkout go1.6.2
cd src
export GOARCH=arm64
export GOROOT_BOOTSTRAP=/usr/local/go
export GOOS=linux
./make.bash
cd ../..
tar -cvf go1.6.2.linux-arm64.tar ./go
gzip go1.6.2.linux-arm64.tar 
  • Use sftp or scp on the ARM64 device to get the tar.gz file
  • Then install and set it up on ARM64:
tar -zxvf go1.6.2.linux-arm64.tar.gz
sudo mv go /usr/local/
cd /usr/local/go/bin/linux_arm64
sudo cp * ..
cd
export GOROOT=/usr/local/go
mkdir -p ~/gitwork/go/src
mkdir ~/gitwork/go/bin
mkdir ~/gitwork/go/pkg
export GOPATH=~/gitwork/go
go version
@bo01ean
Copy link

bo01ean commented Oct 13, 2016

Also worked on my tegra tx1, thanks a bunch 🍺

@truedat101
Copy link

truedat101 commented Mar 11, 2017

Thx, small mods for 1.8 done here: https://gist.github.com/truedat101/5898604b1f7a1ec42d65a75fa6a0b802 , will cover bootstrap build.

@truedat101
Copy link

I'm curious, just realized that the cross build retains the bootstrap platform's go binary (x86 presumably). Why is that? I see the last steps you have are to copy the linux_arm64 binary over the bootstrap one.

@Danara5
Copy link

Danara5 commented Apr 19, 2020

Thanks for this. You saved me a ton of work to get this working on a raspberry pi 3B and go1.10.4 linux/arm64 on Ubuntu 18,04

@sanfx
Copy link

sanfx commented Nov 3, 2020

when you do go install . the binary will go to GOPATH/bin or /home/{USER}/go/bin/ folder.

@doertydoerk
Copy link

Brilliant! Cheers, mate!

@FilipChalupa
Copy link

This worked for me: https://thepro.io/post/how-to-install-latest-go-on-raspberry-pi-os-Kp

Other solutions said that /usr/local/go/bin/go doesn't exist.

@Pearl-Katey
Copy link

Please how do I use the sftp? @conoro

@FilipChalupa
Copy link

What is your other system, the one you are connecting from to your Raspberry or something? Windows? Linux? Mac?

On some you can use scp command. On others more visual tool like FileZilla.

@Pearl-Katey
Copy link

It is linux, I am using the linux in chrome OS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment