Go: unknown subcommand "mod"

I would like to access the Go Module it seems that mod sub command is not found on my system, i was trying to fix it but i couldn’t find proper solution… please help me with your answers.

am using Golang 10.4 version on Ubuntu 18.04

2 Likes
  1. There is no golang version 10.4
  2. Modules are available since 1.11 as an experimental feature (conscious opt in via setting an environment variable) and enabled by default since 1.12.
3 Likes

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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.