英文:
Error when trying to build package from github with go
问题
我正在尝试从GitHub安装软件包。https://github.com/adnanh/webhook
版本
$ go version
go version go1.17.5 linux/amd64
.profile:
export PATH=$PATH:/usr/local/go/bin
尝试:
$ go build github.com/adnanh/webhook
没有必需的模块提供了github.com/adnanh/webhook包:在当前目录或任何父目录中找不到go.mod文件;请参阅'go help modules'
设置
$ go env
GO111MODULE=""
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/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build586084061=/tmp/go-build -gno-record-gcc-switches"
有什么问题?
而且我在/root/目录下没有带有pkg和bin子文件夹的go文件夹。
英文:
I am trying to install package from github. https://github.com/adnanh/webhook
Version
$ go version
go version go1.17.5 linux/amd64
.profile:
export PATH=$PATH:/usr/local/go/bin
Try:
$ go build github.com/adnanh/webhook
no required module provides package github.com/adnanh/webhook: go.mod file not found
in current directory or any parent directory; see 'go help modules'
Settings
$ go env
GO111MODULE=""
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/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build586084061=/tmp/go-build -gno-record-gcc-switches"
where is a problem?
And I don't have go folder in /root/ with pkg and bin subfolders
答案1
得分: 2
只有go install
可以在任何项目之外工作(没有本地的.go.mod文件)。
自Go 1.16以来,如果参数带有版本后缀(如@latest
或@v1.0.0
),go install
会在模块感知模式下构建包,忽略当前目录或任何父目录中的go.mod
文件。
这对于安装可执行文件而不影响主模块的依赖项非常有用。
go build
应该在本地项目中使用,使用其go.mod
依赖项列表。它会编译一个包,但不会安装它。
英文:
Only go install
can work outside of any project (without a local .go.mod$
> Since Go 1.16, if the arguments have version suffixes (like @latest
or @v1.0.0
), go install
builds packages in module-aware mode, ignoring the go.mod
file in the current directory or any parent directory if there is one.
>
> This is useful for installing executables without affecting the dependencies of the main module.
go build
is meant to be used within a local project, with its go.mod
dependencies list. It compiles, but does not install, a package.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论