运行”go mod init”时出现未知子命令”mod”错误。

huangapple go评论104阅读模式
英文:

Unknown subcommand "mod" error while running go mod init

问题

我已经在我的Ubuntu上使用sudo apt install golang-go安装了Go语言。

安装成功。当我运行go version时,我得到的是go version go1.10.4 linux/amd64

但是当我尝试运行go mod init projectName时,我得到了以下错误信息:error go: unknown subcommand "mod"

我需要安装mod包吗?还是我漏掉了什么?我已经按照Christophe在这个论坛中给出的解决方案进行了尝试,但对我没有起作用。

英文:

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.

答案1

得分: 19

Go 1.11中添加了初步的模块支持,因此Go 1.10不支持mod子命令。

您需要安装一个更新的、最好是最新的1.14版本的Go。可以从官方下载页面获取。Go 1.10甚至已经不再受支持(不会接收安全补丁)。

操作系统的预装包通常滞后于新版本发布。我建议始终从官方页面获取Go。

英文:

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.

答案2

得分: 1

因为对于go-modules的初步支持是在1.11和1.12版本中引入的。

更多信息请参阅此处

我建议您直接使用golang官方提供的Linux构建版本进行安装

英文:

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

huangapple
  • 本文由 发表于 2020年2月26日 17:34:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/60410729.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定