英文:
Where does go install the binaries of go get?
问题
我想安装ginkgo命令,我尝试了以下步骤。
$ go get github.com/onsi/ginkgo/ginkgo
go: 正在下载 golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
go: 升级 github.com/onsi/ginkgo v1.12.1 => v1.16.5
但我不确定ginkgo命令安装在哪里。
这是我的环境设置。
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/senthilx/.cache/go-build"
GOENV="/home/senthilx/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/senthilx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/senthilx/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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-build1077100959=/tmp/go-build -gno-record-gcc-switches"
该命令没有在我的"GOPATH"中安装ginkgo。
$ ls
pkg
$ find . -type f -name ginkgo
$
<details>
<summary>英文:</summary>
I wanted to install ginkgo command and I tried.
$ go get github.com/onsi/ginkgo/ginkgo
go: downloading golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
go: upgraded github.com/onsi/ginkgo v1.12.1 => v1.16.5
But I am not sure where the ginkgo command is installed.
Here is my environment.
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/senthilx/.cache/go-build"
GOENV="/home/senthilx/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/senthilx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/senthilx/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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-build1077100959=/tmp/go-build -gno-record-gcc-switches"
The command didn't install ginkgo in my "GOPATH"
$ ls
pkg
$ find . -type f -name ginkgo
$
</details>
# 答案1
**得分**: 3
`go get`命令仅用于更新模块依赖项,不会安装任何二进制文件。安装`main`包的能力在`go1.17`中已被弃用。在模块内部,`go get`命令将显示对依赖项所做的任何更改,如下所示:
```shell
go: downloading golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
go: upgraded github.com/onsi/ginkgo v1.12.1 => v1.16.5
如果你尝试在模块外部使用go get
,将返回以下错误:
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'.
英文:
The go get
command is only used for updating module dependencies, it does not install any binaries. The ability to install main
packages was deprecated in go1.17
. Within a module the go get
command will show any changes made to the dependencies, as you can see by the output:
go: downloading golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
go: upgraded github.com/onsi/ginkgo v1.12.1 => v1.16.5
If you try to use go get
outside of a module it will return the error:
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'.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论