我可以帮你解决”go build”和”go install”无法正常工作的问题。

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

How I can fix the trouble with go build and go install doesnt work

问题

大家好,我决定下载一个工具 - https://github.com/Charlie-belmer/nosqli(用GO编写)来进行我的渗透测试练习(它在我的/home/user目录下创建了nosqli目录)。
然后发现它不起作用。所以我开始修复这个问题,但卡住了:

当我运行"go install"时,什么都没有发生,没有任何错误消息。现在它给了我这个错误:

go install main.go:19:8: cannot find package "github.com/Charlie-belmer/nosqli/cmd" in any of: /usr/lib/go-1.17/src/github.com/Charlie-belmer/nosqli/cmd (from $GOROOT) /root/go/src/github.com/Charlie-belmer/nosqli/cmd (from $GOPATH)

使用"go build"也是同样的情况。

# go version
go version go1.17.6 linux/amd64

go env(输出):

GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.17"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.17/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3159993699=/tmp/go-build -gno-record-gcc-switches"

我以前从未使用过Go,完全卡住了,尝试阅读一些指南,但没有结果。

英文:

Hello guys decided to download one tool - https://github.com/Charlie-belmer/nosqli (wrote on GO) for my pentest practice (it's made the nosqli directory in my /home/user).
And found out that it's doesn't work. So I've started to fix this problem and stucked:

when I did "go install" it did nothing I mean literally without error msg etc. Now it gaves me that:

go install main.go:19:8: cannot find package "github.com/Charlie-belmer/nosqli/cmd" in any of: /usr/lib/go-1.17/src/github.com/Charlie-belmer/nosqli/cmd (from $GOROOT) /root/go/src/github.com/Charlie-belmer/nosqli/cmd (from $GOPATH)

And same situation with go build.

**# go version
go version go1.17.6 linux/amd64**

**go env** (output):

GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.17"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.17/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3159993699=/tmp/go-build -gno-record-gcc-switches"

I've never used Go before and absolutely stucked, tried to read so guids but resultless.

答案1

得分: 1

你是如何下载这个工具的?你是从Github克隆仓库并尝试构建它吗?如果你只是想使用这个工具,为什么不在这里获取适用于你的操作系统的二进制版本:https://github.com/Charlie-belmer/nosqli/releases/tag/v0.5.4?

如果你真的想要构建它,你需要克隆仓库:

git clone https://github.com/Charlie-belmer/nosqli.git /some/dir

然后运行

cd /some/dir
go build -o nosqli .

go工具会在构建过程中获取所有依赖项并构建二进制文件(命名为-o后面的内容,在这种情况下是nosqli),根本不需要运行go install。在下载依赖项和构建完成后,nosqli二进制文件应该位于/some/dir目录中。

英文:

How did you download the tool? Did you clone the repo from Github and trying to build it? If you just want to use the tool why not grab binary release for your OS here: https://github.com/Charlie-belmer/nosqli/releases/tag/v0.5.4 ?

If you really want to build it, you will need to clone the repository:

git clone https://github.com/Charlie-belmer/nosqli.git /some/dir

and run

cd /some/dir
go build -o nosqli .

go tool will fetch all dependencies as part of process and build the binary (named as whatever comes after -o - in this case nosqli), no need to run go install at all. nosqli binary should then be in /some/dir after downloading dependencies and build finishes.

答案2

得分: 0

通常情况下,您会在您正在开发的软件中安装要使用的软件包。
假设您想要使用某个软件包。
然后命令将是
go install 完整的软件包名称
例如:
go install github.com/marcelloh/gotest@latest

英文:

Normally you would install a package that you want to use in the software you're making.
Let's assume you want to use some package.
Then the command will be
go install the_complete_package
example:
go install github.com/marcelloh/gotest@latest

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

发表评论

匿名网友

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

确定