安装Go包时出现问题

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

Issue in installing a go package

问题

所以,最近我开始跟着一个视频教程学习,我对Go语言还比较新,尝试安装了fork版本的bolt db,使用了以下命令:
$ go get go.etcd.io/bbolt/...
注意:我想使用这个特定的版本,但是我遇到了一个错误,错误信息如下:

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'

我阅读了一些GitHub的问题,其中说到go get已经被弃用了,那么我该如何解决这个问题呢?我还尝试了一些其他方法,比如使用以下命令:
go install go.etcd.io/bbolt/...

英文:

So,I recently started following a video tutorial and i am fairly new to golang and tried installing the forked version of bolt db using
$ go get go.etcd.io/bbolt/...
Note : I want to use this specific version
but i am getting an error which says

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' 

I read a few GitHub issues which say that go get is deprecated so how do I resolve this ?
I also tried few other things such as
go install go.etcd.io/bbolt/...

答案1

得分: 5

Go模块是当今的标准。特别是如果你是Go的新手,不要浪费时间在不使用(和教授)它们的材料上。

在你的项目仓库根目录中运行go mod init yourproject。这将创建一个go.mod文件。

一旦你有了这个文件,你可以选择:

  • 在源代码中导入go.etcd.io/bbolt,然后运行go mod tidy。Go工具会找到并将模块添加到你的依赖项(go.mod文件)中。这在入门教程中有详细描述。
  • 直接运行go get go.etcd.io/bbolt,这也会更新依赖项。

使用Go模块系列详细解释了工作流程,并在将命令从过时的材料转换时非常有帮助。

英文:

Go modules are today's standard. Especially if you are new to Go; do not spend time on material that do not use (and teach) them.

Run go mod init yourproject
in your project repository root directory. This will create go.mod file.

Once you have that you can either:

  • import go.etcd.io/bbolt in source code and then run go mod tidy. Go tool will find and add module to your dependencies (go.mod file). This is described in Getting started tutorial.
  • run go get go.etcd.io/bbolt directly, that will update dependencies too.

Using Go Modules series explains workflow in detail and will be helpful when converting commands from an outdated material.

huangapple
  • 本文由 发表于 2022年6月13日 10:55:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/72597368.html
匿名

发表评论

匿名网友

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

确定