无法安装Go模块,使用`go get -u`和`go install`命令。

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

can't install a go module, using get -u and install

问题

我想安装go-fastping,但是当我尝试使用go get -u github.com/tatsushid/go-fastping时,显示出以下错误:

go: 在当前目录或任何父目录中找不到go.mod文件。
        在模块之外,不再支持'go get'。
        要构建和安装命令,请使用带有版本的'go install',
        例如'go install example.com/cmd@latest'
        有关更多信息,请参阅https://golang.org/doc/go-get-install-deprecation
        或运行'go help get'或'go help install'。

所以我改为使用以下命令进行安装:
go install github.com/tatsushid/go-fastping

尝试'go install github.com/tatsushid/go-fastping@latest'以安装最新版本

然后我改为使用以下命令:go install github.com/tatsushid/go-fastping@latest

这样做后,它可以正常工作,但是当我尝试在代码中添加它时,它显示模块未安装。

英文:

I want to install go-fastping, but when I try using
go get -u github.com/tatsushid/go-fastping, this error gets displayed:

go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

so I changed to install:
go install github.com/tatsushid/go-fastping

Try 'go install github.com/tatsushid/go-fastping@latest' to install the latest version 

and after I did changed to: go install github.com/tatsushid/go-fastping@latest

it worked but when I try to add it in the code it says that the module is not installed.

答案1

得分: 1

你的项目很可能没有一个go.mod文件。

在项目的根目录下运行go mod init <module-name>来创建一个模块,然后你可以运行go get -u github.com/tatsushid/go-fastping来将这个依赖项添加到你的项目中。

英文:

Your project most likely doesn't have a go.mod file.

Inside the root of your project run go mod init &lt;module-name&gt; to create a module and then you can run go get -u github.com/tatsushid/go-fastping to add this dependency to your project.

huangapple
  • 本文由 发表于 2022年12月26日 22:14:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/74921148.html
匿名

发表评论

匿名网友

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

确定