go get命令安装的二进制文件会被放置在$GOPATH/bin目录下。

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

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&#39;t install ginkgo in my &quot;GOPATH&quot; 

$ 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 =&gt; 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.
	&#39;go get&#39; is no longer supported outside a module.
	To build and install a command, use &#39;go install&#39; with a version,
	like &#39;go install example.com/cmd@latest&#39;
	For more information, see https://golang.org/doc/go-get-install-deprecation
	or run &#39;go help get&#39; or &#39;go help install&#39;.

huangapple
  • 本文由 发表于 2022年4月14日 01:58:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/71861952.html
匿名

发表评论

匿名网友

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

确定