5

The "gopls" command is not available. Run "go get -v golang.org/x/tools/gopls" to install.

I'm running on go 1.14. Not sure what will happen, if I follow the instruction.

enter image description here


Installing 1 tool at the configured GOBIN: /usr/local/go/bin in module mode.
  gopls

Installing golang.org/x/tools/gopls FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "/usr/local/go/bin/go get -v golang.org/x/tools/gopls",
 "stdout": "",
 "stderr": "go: downloading golang.org/x/tools/gopls v0.6.9\ngo: golang.org/x/tools/gopls upgrade => v0.6.9\ngo: downloading golang.org/x/tools v0.1.1-0.20210319172145-bda8f5cee399
...

1 tools failed to install.

gopls: failed to install gopls(golang.org/x/tools/gopls): Error: Command failed: /usr/local/go/bin/go get -v golang.org/x/tools/gopls
go: downloading golang.org/x/tools/gopls v0.6.9
go: golang.org/x/tools/gopls upgrade => v0.6.9
go: downloading golang.org/x/tools v0.1.1-0.20210319172145-bda8f5cee399
go: downloading golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
go: downloading honnef.co/go/tools v0.1.1
go: downloading golang.org/x/mod v0.4.1
golang.org/x/mod/semver
...

go get golang.org/x/tools/gopls: copying /var/folders/gq/bwl3jmx562x5twchgxvb6mlh0000gn/T/go-build703164122/b001/exe/a.out: open /usr/local/go/bin/gopls: permission denied
 no output 
Flexo
  • 87,323
  • 22
  • 191
  • 272
Nicole
  • 127
  • 1
  • 1
  • 7
  • 9
    How about running `go get -v golang.org/x/tools/gopls` to install gopls? No, seriously. – jubnzv Mar 17 '21 at 07:25
  • 2
    actually, I am not sure, what the gopls is used for ... – Nicole Mar 21 '21 at 07:36
  • Then read about it: https://pkg.go.dev/golang.org/x/tools/gopls – jubnzv Mar 21 '21 at 07:45
  • I was getting similar error about `goplay` command. So I ran `go get -v github.com/haya14busa/goplay/cmd/goplay` from command prompt as it was mentioned in the error message and it worked fine for me. – RBT Aug 17 '21 at 07:19

3 Answers3

15

I had the same problem and solved it with:

go install -v golang.org/x/tools/gopls@latest

if you get the error:

x\tools@v0.1.13-0.20220811140653-b901dff69f70\internal\lsp\source\hover.go:23:2: module golang.org/x/text@latest found (v0.3.7), but does not contain package golang.org/x/text/unicode/runenames

try using:

go clean -modcache
go install -v golang.org/x/tools/gopls@latest
Bas
  • 358
  • 3
  • 7
10

The extension depends on other tools to provide necessary features. gopls is one of the core tools necessary to provide language features like code completion, navigation, search, etc for go language. See the list of tools the extension depends on: https://github.com/golang/vscode-go/blob/master/docs/tools.md

"Install" will install the 'gopls'. "Install All" will install all the missing tools.

If you are using go1.14, either click the button (or run "Go: Install/Update Tools" command from the command palette) or, install tools in module mode with the following command (not just go get because with go1.14, the go command will try to install the tool in GOPATH mode which isn't what you want.)

cd /tmp/
GO111MODULE=on go get golang.org/x/tools/gopls
Hana
  • 565
  • 5
  • 9
  • when I just click the "Install" option button, provided in vs code, I got below info : – Nicole Mar 28 '21 at 06:23
  • Yes, need privilege and network, both ok. Solved this issue in terminal. Not in IDE. – Nicole Mar 28 '21 at 07:08
  • I have followed the step of `cd /tmp GO111MODULE=on go get golang.org/x/tools/gopls` and no error met, why vs code still throw the warn window out? – Nicole Mar 28 '21 at 07:16
  • gopls must be installed into the GOPATH that VSC uses, e.g., run the install when logged in as the same user that runs VSC – SVUser May 23 '21 at 16:38
1

Here I solved using the command brew install gopls

  • Error: gopls: Failed to download resource "gopls_bottle_manifest" Download failed: https://ghcr.io/v2/homebrew/core/gopls/manifests/0.11.0 – Vzans Mar 15 '23 at 15:04