Go工具安装成功,但在$GOPATH/bin目录中没有显示。

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

Go Tools installed successfully but not appear in $GOPATH/bin

问题

我在vscode中安装了go工具,并且终端显示工具已成功安装:

工具环境:GOPATH=/home/spindrift/go
在模块模式下安装1个工具到/home/spindrift/go/bin。
  gopls

安装golang.org/x/tools/gopls (gopls) 成功

所有工具已成功安装。您已准备就绪:)。

但是安装后,vscode仍然显示"gopls被查询但缺失"。

所以我查看了$GOPATH/bin目录,里面只有dlv-dap

我检查了我的配置工具:

检查配置的工具....
GOBIN: 未定义
toolsGopath: 
gopath: /home/spindrift/go
GOROOT: /usr/local/go
PATH: /usr/local/go/bin:/home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin
PATH (vscode启动时): /home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin:/usr/local/go/bin

	go:	/usr/local/go/bin/go: go version go1.18.1 linux/amd64

	gopkgs:	未安装
	go-outline:	未安装
	gotests:	未安装
	gomodifytags:	未安装
	impl:	未安装
	goplay:	未安装
	dlv:	未安装
	dlv-dap:	/home/spindrift/go/bin/dlv-dap: go1.18.1
		path	github.com/go-delve/delve/cmd/dlv
		mod	github.com/go-delve/delve	v1.8.3-0.20220413222856-313815782614	h1:J92Zq5+vc+zzd0Gn69RxVUUC3orKgciGmurMPUSci4I=
		dep	github.com/cilium/ebpf	v0.7.0	h1:1k/q3ATgxSXRdrmPfH8d7YK0GfqVsEKZAX9dQZvs56k=
		dep	github.com/cosiner/argv	v0.1.0	h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
		dep	github.com/cpuguy83/go-md2man/v2	v2.0.0	h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
		dep	github.com/derekparker/trie	v0.0.0-20200317170641-1fdf38b7b0e9	h1:G765iDCq7bP5opdrPkXk+4V3yfkgV9iGFuheWZ/X/zY=
		dep	github.com/go-delve/liner	v1.2.2-1	h1:0hGpZh6vjI6LFTlXuHFCX9PebaluzDzps2owdMrrSuk=
		dep	github.com/google/go-dap	v0.6.0	h1:Y1RHGUtv3R8y6sXq2dtGRMYrFB2hSqyFVws7jucrzX4=
		dep	github.com/hashicorp/golang-lru	v0.5.4	h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
		dep	github.com/mattn/go-isatty	v0.0.3	h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
		dep	github.com/mattn/go-runewidth	v0.0.13	h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
		dep	github.com/rivo/uniseg	v0.2.0	h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
		dep	github.com/russross/blackfriday/v2	v2.0.1	h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
		dep	github.com/shurcooL/sanitized_anchor_name	v1.0.0	h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
		dep	github.com/sirupsen/logrus	v1.6.0	h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
		dep	github.com/spf13/cobra	v1.1.3	h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
		dep	github.com/spf13/pflag	v1.0.5	h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
		dep	go.starlark.net	v0.0.0-20200821142938-949cc6f4b097	h1:YiRMXXgG+Pg26t1fjq+iAjaauKWMC9cmGFrtOEuwDDg=
		dep	golang.org/x/arch	v0.0.0-20190927153633-4e8777c89be4	h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI=
		dep	golang.org/x/sys	v0.0.0-20211117180635-dee7805ff2e1	h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI=
		dep	gopkg.in/yaml.v2	v2.4.0	h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
		build	-compiler=gc
		build	CGO_ENABLED=1
		build	CGO_CFLAGS=
		build	CGO_CPPFLAGS=
		build	CGO_CXXFLAGS=
		build	CGO_LDFLAGS=
		build	GOARCH=amd64
		build	GOOS=linux
		build	GOAMD64=v1
	
	staticcheck:	未安装
	gopls:	未安装

看起来我安装go工具失败了。我尝试了几次,但问题仍未解决。

这是我的go env

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/spindrift/.cache/go-build"
GOENV="/home/spindrift/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/spindrift/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/spindrift/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,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=""
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-build1163911802=/tmp/go-build -gno-record-gcc-switches"
英文:

I installed go tools in vscode and the terminal showed that the tools are installed successfully:

Tools environment: GOPATH=/home/spindrift/go
Installing 1 tool at /home/spindrift/go/bin in module mode.
  gopls

Installing golang.org/x/tools/gopls (gopls) SUCCEEDED

All tools successfully installed. You are ready to Go :).

But after installing the vscode keep showing gopls is inquired but missing

So I take a look at $GOPATH/bin, and there's only dlv-dap in it!

I check my configured tools:

Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /home/spindrift/go
GOROOT: /usr/local/go
PATH: /usr/local/go/bin:/home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin
PATH (vscode launched with): /home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin:/usr/local/go/bin

	go:	/usr/local/go/bin/go: go version go1.18.1 linux/amd64

	gopkgs:	not installed
	go-outline:	not installed
	gotests:	not installed
	gomodifytags:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	not installed
	dlv-dap:	/home/spindrift/go/bin/dlv-dap: go1.18.1
		path	github.com/go-delve/delve/cmd/dlv
		mod	github.com/go-delve/delve	v1.8.3-0.20220413222856-313815782614	h1:J92Zq5+vc+zzd0Gn69RxVUUC3orKgciGmurMPUSci4I=
		dep	github.com/cilium/ebpf	v0.7.0	h1:1k/q3ATgxSXRdrmPfH8d7YK0GfqVsEKZAX9dQZvs56k=
		dep	github.com/cosiner/argv	v0.1.0	h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
		dep	github.com/cpuguy83/go-md2man/v2	v2.0.0	h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
		dep	github.com/derekparker/trie	v0.0.0-20200317170641-1fdf38b7b0e9	h1:G765iDCq7bP5opdrPkXk+4V3yfkgV9iGFuheWZ/X/zY=
		dep	github.com/go-delve/liner	v1.2.2-1	h1:0hGpZh6vjI6LFTlXuHFCX9PebaluzDzps2owdMrrSuk=
		dep	github.com/google/go-dap	v0.6.0	h1:Y1RHGUtv3R8y6sXq2dtGRMYrFB2hSqyFVws7jucrzX4=
		dep	github.com/hashicorp/golang-lru	v0.5.4	h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
		dep	github.com/mattn/go-isatty	v0.0.3	h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
		dep	github.com/mattn/go-runewidth	v0.0.13	h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
		dep	github.com/rivo/uniseg	v0.2.0	h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
		dep	github.com/russross/blackfriday/v2	v2.0.1	h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
		dep	github.com/shurcooL/sanitized_anchor_name	v1.0.0	h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
		dep	github.com/sirupsen/logrus	v1.6.0	h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
		dep	github.com/spf13/cobra	v1.1.3	h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
		dep	github.com/spf13/pflag	v1.0.5	h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
		dep	go.starlark.net	v0.0.0-20200821142938-949cc6f4b097	h1:YiRMXXgG+Pg26t1fjq+iAjaauKWMC9cmGFrtOEuwDDg=
		dep	golang.org/x/arch	v0.0.0-20190927153633-4e8777c89be4	h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI=
		dep	golang.org/x/sys	v0.0.0-20211117180635-dee7805ff2e1	h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI=
		dep	gopkg.in/yaml.v2	v2.4.0	h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
		build	-compiler=gc
		build	CGO_ENABLED=1
		build	CGO_CFLAGS=
		build	CGO_CPPFLAGS=
		build	CGO_CXXFLAGS=
		build	CGO_LDFLAGS=
		build	GOARCH=amd64
		build	GOOS=linux
		build	GOAMD64=v1
	
	staticcheck:	not installed
	gopls:	not installed

It seems that I failed to install go tools. I tried several times but the problem still unsolved.

Here's my go env

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/spindrift/.cache/go-build"
GOENV="/home/spindrift/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/spindrift/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/spindrift/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,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=""
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-build1163911802=/tmp/go-build -gno-record-gcc-switches"

答案1

得分: 4

这是在使用go 1.18时发生的go扩展中的一个错误。在最新版本的vscode-go中已经修复了这个问题,详细信息请参见1和[2]。

更新vscode和go扩展(vscode-go)应该可以解决你的问题(就像对我来说一样)。

1 https://github.com/golang/vscode-go/issues/2143

[2] https://github.com/golang/vscode-go/commit/656865daa974f43e8e88310e5076f3f0c4936c73

英文:

This is a bug in the go extension which occurs when using go 1.18. It has been fixed in recent versions of vscode-go, for details see 1 and [2].

Updating vscode and the go extension (vscode-go) should resolve your problem (as it did for me).

1 https://github.com/golang/vscode-go/issues/2143

[2] https://github.com/golang/vscode-go/commit/656865daa974f43e8e88310e5076f3f0c4936c73

答案2

得分: 1

GOBIN在您的$PATH中不存在。

最简单的方法是在您的.bashrc / .zshrc文件中添加一行代码到$HOME路径中:

PATH=$PATH:$HOME

在此处了解更多关于$PATH的信息:这里

英文:

GOBIN is not present in your $PATH.

the easiest way is to add one more line to your .bashrc / .zshrc in $HOME

PATH = $PATH:$HOME

learn more on $PATH here

答案3

得分: 0

一些配置是从"GOENV"文件中获取的。
确保该文件中的参数是有效的,特别是要查找其中的"GOROOT"。
它应该与你的GO可执行文件路径完全匹配。(在大多数情况下,它可能是/usr/local/go)

如果无效,请更新数值并重试。

英文:

Some configurations are fetched from "GOENV" file.
Make sure params in that file are valid, Especially look for "GOROOT" in it.
It should exactly match your GO executable path. (In most cases it could be /usr/local/go)

If not valid, update values and try again.

答案4

得分: -1

gopls存在于GOPATH和GOROOT中,但是VS Code仍然抱怨找不到gopls。

配置的工具输出显示gopls和其他工具已经正确安装。
go版本为1.17.12。

英文:

The gopls is present in GOPATH and GOROOT, but still VS Code complains about not being able to find gopls.

Configured tools output shows gopls and other tools properly installed.
go version 1.17.12

huangapple
  • 本文由 发表于 2022年4月18日 21:59:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/71912794.html
匿名

发表评论

匿名网友

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

确定