英文:
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 <module-name>
to create a module and then you can run go get -u github.com/tatsushid/go-fastping
to add this dependency to your project.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论