It’s quite easy to install the Go language on Ubuntu and similar Linuxes. In fact, Ubuntu has an old version straight out of apt-get
.
However, if you want to install the latest, maybe you want to download the latest and install it in a clean way. Here’s how I chose to do it - YMMV.
#!/bin/bash -xe
V=go${1:-1.1}
if fgrep $V /usr/local/go/VERSION; then
echo Go $V is already installed in /usr/local/go
echo To uninstall or upgrade, first
echo " sudo rm -rf /usr/local/go"
else
echo Installing Go programming language $V ...
set -e
cd /usr/local
sudo rm -rf go
case `uname -m` in
x86_64) A=linux-amd64 ;;
368|586|686) A=linux-386 ;;
*) echo unsupported:
uname -m
exit 1
;;
esac
U=http://go.googlecode.com/files/$V.$A.tar.gz
echo Downloading and installing $U...
curl -sSf $U | sudo tar zxvf -
fi
echo Add Go to path eg
echo export PATH=$PATH:/usr/local/go/bin
export PATH=/usr/local/go/bin:$PATH
It’s useful to have ‘gorun’ installed too…
#!/bin/bash -e
mkdir -p tmp-gorun.$$
cd tmp-gorun.$$
export GOPATH=$PWD
export PATH=$PATH:$PWD/bin
go get launchpad.net/gorun
[ -x bin/gorun ] || echo "Failed to build gorun"
sudo rsync -av bin/gorun /usr/local/bin
cd ..
rm -rf tmp-gorun.$$
This includes the gorun
tool, allowing scripts to start with #!/usr/local/bin/gorun
.
Raspberry Pi Go
Now, the next task is how to build the Go tools for Arm on a Raspberry Pi… Here are some useful instructions.
Once your Pi is running Rasbian, you might like to follow these steps:
sudo apt-get install -y mercurial gcc libc6-dev
hg clone https://code.google.com/p/go
cd go/src
bash -x ./all.bash
Ref: Installing Go from source
Edit: Updated for Go 1.1
comments powered by Disqus