TQ
dev.com

Blog about software development

Subscribe

Upgrading Go 1.6 in Ubuntu 16.04

14 Feb 2018 - by 'Maurits van der Schee'

Go is an awesome new language that I love to write code in. I'm working on Ubuntu 16.04 and it comes with Go version 1.6. This works fine, until you need something new, such as the "context" package. In this post I'll share the commands needed to upgrade your Go version.

Installing Go 1.6 in Ubuntu 16.04

To install go 1.6 in Ubuntu 16.04 from the repository run:

sudo apt-get install golang golang-golang-x-tools

Set your "GOPATH" and "GOROOT" by adjusting your "~/.bashrc" file so that it reads:

export GOPATH=~/go
export GOROOT=/usr/lib/go-1.6/
export PATH=$PATH:$GOPATH/bin:$GOROOT/bin

Now create your go directory and your first project:

mkdir -p ~/go/src/github.com/mevdschee/hellogo
nano ~/go/src/github.com/mevdschee/hellogo/main.go

Copy-paste the "hello world" code:

package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

Now install Visual Studio Code with the "Go" extension, open the folder and get coding!

Upgrading Go 1.6 in Ubuntu 16.04

Issue the following commands to replacing your Ubuntu installed go 1.6 with a newer version:

go get gopkg.in/niemeyer/godeb.v1/cmd/godeb
sudo apt-get purge golang-go golang-golang-x-tools
sudo apt-get autoremove
godeb list
godeb install 1.9.4

You don't need to set "GOROOT" in newer versions, so you may adjust your "~/.bashrc" file to read:

export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin

Now restart your Visual Studio Code and update your tools (it will prompt for that). That's it!

NB: If you ever need a newer version you can simply run: "godeb install 1.10"


PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.