Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown subcommand "mod" error while running go mod init

Tags:

go

go-modules

I have installed the go language in my ubuntu using sudo apt install golang-go.

It was successfully installed. When i run go version I am getting go version go1.10.4 linux/amd64

but when i tried running go mod init projectName I am getting the following error go: unknown subcommand "mod"

Do I need to install mod package or am i missing something? I have implemented the solution given by christophe in this forum but it didn't work for me.

like image 888
this is yash Avatar asked Feb 26 '20 09:02

this is yash


People also ask

What is go mod init?

The go mod init command creates a go. mod file to track your code's dependencies. So far, the file includes only the name of your module and the Go version your code supports. But as you add dependencies, the go. mod file will list the versions your code depends on.

Where should I run go mod init?

mod file within the mymodule directory to define the Go module itself. To do this, you'll use the go tool's mod init command and provide it with the module's name, which in this case is mymodule .

What does go mod tidy do?

go mod tidy ensures that the go. mod file matches the source code in the module. It adds any missing module requirements necessary to build the current module's packages and dependencies, if there are some not used dependencies go mod tidy will remove those from go.


2 Answers

Preliminary module support was added in Go 1.11, so Go 1.10 knows no mod subcommand.

You need to install a newer, preferably the newest 1.14 version of Go. Get it from the official downloads page. Go 1.10 is not even supported anymore (doesn't receive security patches).

The prepared packages of OSes usually lag behind new releases. I'd advise to always get Go from the official page.

like image 175
icza Avatar answered Oct 06 '22 06:10

icza


Because preliminary support for go-modules came in version 1.11 and 1.12.

More here

I suggest that you install using the linux build directly from golang

like image 25
Kelsnare Avatar answered Oct 06 '22 05:10

Kelsnare