Building / Installing Go on the Raspberry Pi or Ubuntu
############################################################################### | |
# 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} |
This comment has been minimized.
This comment has been minimized.
Bug on line 53 It should not have |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
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!