Visual Studio Code using ?wrong? PATH, not finding GOPATH

I have go installed.
$ which go
/usr/bin/go
Installed Visual Studio Code (VSC) bundle, 1.40.1
Launch Visual Studio Code from options or install launch.
VSC emits this message at bottom right of its UI:
Failed to run “go env” to find GOPATH as the “go” binary cannot be found in either GOROOT(/usr/lib/golang) or PATH(/app/bin:/usr/bin:/home/mark/.var/app/com.visualstudio.code/data/node_modules/bin)

It does not looke like it is using my PATH. The reported error path does not match my environment PATH. A terminal session:
go env | grep GOPATH GOPATH="/home/mark/gocode" echo $PATH
/usr/local/bin:/usr/bin/haswell:/usr/bin:/opt/3rd-party/bin:/home/mark/bin:/home/mark/gocode/bin:/home/mark/flutter/bin:/usr/share/code/bin

A tar file of VSC 1.40, unpacked into a directory and executed from /home/mark/bin/VSCode-linux-x64.1.40.0/bin as ./code does not have this problem.

The flatpak VSCode cannot recognize external PATH.

1 Like

Is there a workaround for this? Perhaps a way to inject PATH? Place a link to Go in the PATH list emitted by VSCode on the display?

1 Like

I understand that, and I am running the tarball. Does this mean the flatpak version is useless to me? I think I recall there are redistribution or update issues with the not-flatpak version?

Will there be a notice on the community at some point if we resolve this issue?

Thank you.

Flatpak programs are sandboxed and this is a problem of flatpak instead of this distribution. I don’t know what is the problem with the tarball VSCode. As long as you don’t feel it, there’s no problem.

Does someone find the way to set GOPATH in VSCode?
I’m new to Linux and it’s all is complicated for me.

This distro is not intended for desktop usage or to be beginner friendly.

Have you ever tried Jetbrain’s GoLand ?

I hear a lot of good things about it.

Yes it is excellent. VSCODE is actually one of the better ones for go as well though …

You don’t do this in VSCODE. Do it in ~/.bashrc

Note: if you’re using the flatpak don’t bother. It won’t work and you’re wasting your time.

On Any Distro

in terminal:

go_version=1.15.6 # check https://golang.org/dl/ for current stable version 
mkdir -p ~/Projects/go/{src,pkg,bin}
curl -sL  "https://golang.org/dl/go${go_version}.linux-amd64.tar.gz" > go.tar.gz
tar -xvf go.tar.gz
sudo mv go/ /usr/local
cat <<'EOF' |  tee -a  ~/.bashrc
export GOROOT=/usr/local/go
export GOPATH=/home/$USER/Projects/go
export PATH=$PATH:$GOROOT/bin
export PATH=$PATH:$GOPATH/bin
EOF

Many thanks for that complete information!