How to update golang on codeanywhere.com with Ubuntu

836 Views Asked by At

How to update golang on codeanywhere.com with Ubuntu 14.04?

The default container uses the version from Ubuntu repos, instead of golang PPA.

As of writing it's 1.6 and the newest version is 1.9.

3

There are 3 best solutions below

0
On

Create and new Blank Container with Ubuntu: enter image description here

Connect to the container with SSH.

Follow the instructions on the official wiki.

First install the add-apt-repository support:

sudo apt-get update
sudo apt-get install -y software-properties-common

Now install the recent version of golang (refer to the wiki for up to date instructions):

sudo add-apt-repository ppa:gophers/archive
sudo apt-get update
sudo apt-get install golang-1.9-go

Make sure to put the binary on PATH, e.g.:

sudo ln -s /usr/lib/go-1.9/bin/go /usr/local/bin/go

Now the newer version should be available:

$ go version
go version go1.9.2 linux/amd64

Add $GOPATH pointing to the workspace and add $GOPATH/bin to $PATH in ~/.profile:

cat << EOF >> ~/.profile
export GOPATH="\$HOME/workspace"
export PATH="\$GOPATH/bin:\$PATH"
EOF

Apply the new ~/.profile:

. ~/.profile

Also make is missing, if you need it:

sudo apt-get install build-essential
0
On

You can easily install the latest golang release in the container by using this script:

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Full details: https://github.com/udhos/update-golang

1
On

(can't comment yet) Just an additional information, the steps in Paweł Prażak's answer work when you run on a Blank Container. If you run them on a Go predefined stack it won't update.

I also recommend to change the GOPATH value to your workspace, running

export GOPATH=$HOME/go

Then run go env to check if the values are correctly updated.

Thanks for the answer by the way, Paweł!