Search code examples
govisual-studio-codego-modules

VSCODE faill to install tools in go module


when starting a go module on VSCode I get prompted to install some tool

enter image description here

choosing install the installation fails, below the logs in vscode terminal

VSCODE keeps yelling at me an "fail to install" stuff, simply because ignores my path as you can see below

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

Installing golang.org/x/tools/gopls FAILED

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: writing stat cache: mkdir /home/go: permission denied
go: downloading golang.org/x/tools/gopls v0.5.1
go: downloading golang.org/x/tools v0.0.0-20201017001424-6003fad69a88
go get golang.org/x/tools/gopls: mkdir /home/go: permission denied
 undefined  

these are my GOPATH and GOROOT

# GOLANG
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH
export PATH=$GOROOT/bin:$PATH

and this is my vscode settings.json

{
    "[dart]": {
        "editor.formatOnSave": true,
        "editor.formatOnType": true,
        "editor.rulers": [
            80
        ],
        "editor.selectionHighlight": false,
        "editor.suggest.snippetsPreventQuickSuggestions": false,
        "editor.suggestSelection": "first",
        "editor.tabCompletion": "onlySnippets",
        "editor.wordBasedSuggestions": false
    },
    "workbench.iconTheme": "material-icon-theme",
    "workbench.colorTheme": "One Dark Pro",
    "dart.sdkPath": "/home/francesco/development/dart",
    "dart.openDevTools": "flutter",
    "go.formatTool": "goimports",
    "dart.checkForSdkUpdates": false,
    "go.useLanguageServer": true,
    "go.inferGopath": false,
    "go.gopath": "/home/go",
    "go.goroot": "/usr/local/go"
}

what action should I take to fix the error?


Solution

  • Your error is:

    go: writing stat cache: mkdir /home/go: permission denied
    

    Go tries to write to /home/go. This folder is derived from:

    export GOPATH=$HOME/go
    

    So it looks your $HOME doesn't point to your home folder. GOPATH should point to a folder where you have write permission, because the module cache is located under GOPATH. So it should point to a folder under your user home, e.g. /home/francesco/go.