Golang Development Environment with GVM in Ubuntu 18.10

It has been a while since I last looked at development using Golang. Since I was reading some Golang code during this period, might as well look at setting the Golang development environment in Ubuntu 18.10.

There are several ways to setup your Golang development environment. Two good choices are using the default package installation or using Go Version Manager (GVM). There are several options to choose from default packages management, either by DEB or Snap as shown below.
$ go

Command 'go' not found, but can be installed with:

sudo snap install go         # version 1.10.3, or
sudo apt  install golang-go
sudo apt  install gccgo-go 
......

However, if you want several different Go versions co-exist within the same machine or want to get the latest greatest version, Go Version Manager (GVM) will be the preferred choices. While my preference choice is to use existing package manager (simpler and easier), it's good to look into other approaches. Hence, our focus of this post will be on GVM.

Some prerequisites. Please install and remove some packages (if you have existing Go installed).
$ sudo apt install curl git mercurial make binutils bison gcc build-essential
$ sudo apt remove golang-go
$ sudo snap remove go

Next, download and install the gvm installer. Yes, we all know downloading and running Bash script from the Interweb is rather stupid and insecure. But what the heck.
$ zsh < < (curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Cloning from https://github.com/moovweb/gvm.git to /home/ang/.gvm
Created profile for existing install of Go at "/snap/go/3039"
Installed GVM v1.0.22

Please restart your terminal session or to get started right away run
 `source /home/ang/.gvm/scripts/gvm`

Reload your Bash file settings.
$ source ~/.zshrc

Find the most recent 5 stable releases.
$ gvm listall | grep -v -E '(release|beta|rc)' | sort -rn -t. -k2,2 | head -n 5
   go1.11.2
   go1.11.1
   go1.11
   go1.10.5
   go1.10.4

Install the binary.
$ gvm install go1.11.2 --binary

Set and use the default binary.
$ gvm use go1.11.2 --default
Now using version go1.11.2

Now check your installation.
$ which go
/home/ang/.gvm/gos/go1.11.2/bin/go

Now, check your Golang related environment paths.
$ gvm pkgset list

gvm go package sets (go1.11.2)

=> global

See the environment settings of the `global` profile.
$ gvm pkgenv global

If you don't like Gvm and want to nuke the whole installation.
$ gvm implode

No comments:

Post a Comment