登录
首页 >  Golang >  Go问答

尝试通过 get -u 安装 go 模块时遇到了问题

来源:stackoverflow

时间:2024-02-05 21:39:30 315浏览 收藏

Golang不知道大家是否熟悉?今天我将给大家介绍《尝试通过 get -u 安装 go 模块时遇到了问题》,这篇文章主要会讲到等等知识点,如果你在看完本篇文章后,有更好的建议或者发现哪里有问题,希望大家都能积极评论指出,谢谢!希望我们能一起加油进步!

问题内容

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

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'.

所以我改为安装: go 安装 github.com/tatsushid/go-fastping

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

在我更改为:go install github.com/tatsushid/go-fastping@latest

它有效,但是当我尝试将其添加到代码中时,它说该模块尚未安装。


正确答案


您的项目很可能没有 go.mod 文件。

在项目的根目录中运行 go mod init 创建一个模块,然后您可以运行 go get -u github.com/tatsushid/go-fastping 将此依赖项添加到您的项目中。

到这里,我们也就讲完了《尝试通过 get -u 安装 go 模块时遇到了问题》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>