Reputation: 2677
when starting a go module on VSCode I get prompted to install some tool
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?
Upvotes: 4
Views: 6502
Reputation: 714
I recently solved this problem on my Windows machine. At first I had thought it was a file permissions problem. But it was a GOPATH environment variable problem.
I had it set to 2 values: C:\Program Files\Go (which is where I installed Go) and C:.... which was where I wanted all my Go projects to go.
So I removed the first entry. Just leaving GOPATH to point to the place on my hard drive where I wanted all my projects, and hey presto, problems gone, all tools installed correctly.
This may have been due to a previous version of Go not being entirely removed.
Upvotes: 2
Reputation: 418745
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
.
Upvotes: 7