Last active
April 2, 2018 03:54
-
-
Save MartyMacGyver/db36f0bec3fe0187cdc3 to your computer and use it in GitHub Desktop.
Building / Installing Go on the Raspberry Pi or Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# Building Go on the Raspberry Pi | |
############################################################################### | |
# Based on the work of Dave Cheney | |
# http://dave.cheney.net/2015/09/04/building-go-1-5-on-the-raspberry-pi | |
# Also info in the docs: | |
# https://github.com/golang/go/blob/master/src/make.bash | |
############################################################################### | |
### Set project area | |
export MYPROJROOT=~/Projects | |
export MYPKGNAME=go | |
export MYPKGVER=1.10.1 | |
export MYPKGOS=linux | |
export MYPKGARCH=armv6l # Pi, etc. | |
#export MYPKGARCH=amd64 # Intel architectures | |
export MYPKGDEST=/usr/local/${MYPKGNAME}-${MYPKGVER} | |
### Preparation | |
mkdir -p ${MYPROJROOT} | |
cd ${MYPROJROOT} | |
rm -rf ${MYPKGNAME} ${MYPKGNAME}-${MYPKGVER} | |
### Obtaining binaries to use | |
### Option 1: Using the pre-compiled version (1.6.x and later!): | |
# Get the release binaries | |
cd ${MYPROJROOT} | |
wget https://storage.googleapis.com/golang/go${MYPKGVER}.${MYPKGOS}-${MYPKGARCH}.tar.gz | |
tar xzf ${MYPKGNAME}${MYPKGVER}.${MYPKGOS}-${MYPKGARCH}.tar.gz | |
mv ${MYPKGNAME} ${MYPKGNAME}-${MYPKGVER} | |
### Option 2: Building from source: | |
# Lower the ulimit to prevent problems | |
ulimit -s | |
ulimit -s 1024 | |
ulimit -s | |
# Get the source | |
cd ${MYPROJROOT} | |
wget https://storage.googleapis.com/golang/go${MYPKGVER}.src.tar.gz | |
tar xzf ${MYPKGNAME}${MYPKGVER}.src.tar.gz | |
mv ${MYPKGNAME} ${MYPKGNAME}-${MYPKGVER} | |
# Bootstrapping | |
export MYBOOTSTRAP=/usr/local/${MYPKGNAME} | |
if [ ! -d ${MYBOOTSTRAP} ]; then | |
# Never had Go installed | |
cd ${MYPROJROOT} | |
wget http://dave.cheney.net/paste/go-linux-arm-bootstrap-c788a8e.tbz # For ARM | |
tar xjf go-linux-arm-bootstrap-c788a8e.tbz | |
export MYBOOTSTRAP=${MYPROJROOT}/go-linux-arm-bootstrap | |
fi | |
echo ${MYBOOTSTRAP} | |
# Build Go | |
cd ${MYPROJROOT}/${MYPKGNAME}-${MYPKGVER}/src | |
env GO_TEST_TIMEOUT_SCALE=10 GOROOT_BOOTSTRAP=${MYBOOTSTRAP} GOROOT_FINAL=${MYPKGDEST} ./all.bash | |
### Install the package | |
cd ${MYPROJROOT} | |
sudo rm -rf /usr/local/${MYPKGNAME}-${MYPKGVER} | |
sudo cp -rp ${MYPROJROOT}/${MYPKGNAME}-${MYPKGVER} /usr/local | |
sudo chown root:staff /usr/local/${MYPKGNAME}-${MYPKGVER} | |
#sudo chown root:root /usr/local/${MYPKGNAME}-${MYPKGVER} # Ubuntu | |
sudo chmod -R g-s /usr/local/${MYPKGNAME}-${MYPKGVER} | |
sudo rm /usr/local/${MYPKGNAME} | |
sudo ln -s /usr/local/${MYPKGNAME}-${MYPKGVER} /usr/local/${MYPKGNAME} | |
### Test the installation | |
# Ensure the package is in your path (e.g., edit your .profile, then source it with `. ~/.profile`) | |
export PATH=$PATH:/usr/local/go/bin | |
cd $HOME | |
go version | |
go version goX.Y.Z linux/arm | |
# Note: if you get something like "go: cannot find GOROOT directory: /foo/bar/blah" | |
# ensure that path exists. GOROOT_FINAL mediates that (above) | |
### Clean up | |
rm -rf ${MYPROJROOT}/${MYPKGNAME}-${MYPKGVER} |
Bug on line 53 It should not have ~/Projects/
hard coded, it should use ${MYPROJROOT}
instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've learned that gist has a major old bug wherein you don't get notifications for comments to gists.
If you leave a comment, it would be appreciated if you ping me elsewhere so I know to find it!