Go: unknown subcommand "mod"

The go version provided with apt on ubuntu is usually “outdated”.
The recommended way to install the most recent version of go is described here:
https://golang.org/dl/

To get back on your track, here are the steps to follow.

  1. First remove apt installed go : $ sudo apt-get remove go
  2. Download the tar file for linux from the site https://golang.org/dl/
  3. Execute the command $ sudo tar -C /usr/local -xzf
  4. In the file ~/.bash_aliases add the following lines:
    export GOROOT="/usr/local/go"
    export GOBIN="$HOME/go/bin"
    mkdir -p $GOBIN
    export PATH=$PATH:$GOROOT/bin:$GOBIN

This is all you need to get the current latest version of Go 1.13 that support modules. Note that GOPATH is not defined since it’s not needed anymore with modules.
GOBIN is the directory where go commands will be installed or programs compiled with go install.

4 Likes