4

I'm trying to setup GoLand to use WSL 2 as in this guide: https://www.jetbrains.com/help/go/how-to-use-wsl-development-environment-in-product.html

I've installed Go in the Ubuntu distro following the linux instructions on the GoLang website, and go version prints outs the version I downloaded, so it appears that Go is working inside WSL.

printing go version

So now I tried to create a new project in GoLand, and I'm getting errors, which appear to come from the fact that the SDK isn't loaded in GoLand. The guide doesn't offer much guidance on this, so I just tried to add a local SDK.

When I select /usr/local/go I get an error that it's not a valid SDK. invalid sdk dir error

So I created the ~/go directory, and then updated my .zshrc file to export the GOPATH and GOROOT environment variables, even though they already showed up when I ran go env, doing this got them to show up on a simple env call.

But I'm still getting the invalid SDK error like above.

Is there a configuration step I'm missing that isn't spelled out in the guide? I came across this old post about creating symlinks to fake the expected directory structure. I haven't done this because it's a really old post, has comments that say this has been fixed, and seems like a really odd solution.

GridDragon
  • 2,857
  • 2
  • 33
  • 41
  • 2
    "to export the GOPATH and GOROOT environment variables" normal users **NEVER** need to set GOROOT and GOPATH is deprecated. Please read and follow https://golang.org/doc/#getting-started (and do not post images). – Volker Sep 24 '21 at 05:07

2 Answers2

2

Support for Go SDK in WSL2 will be available in the next 2021.3 release, please see GO-10618.

October 2021 update.

2021.3 reaches Early Access Program at the moment. GoLand suggests selecting Go SDK on WSL2 mount if the location of the project is on WSL2 as well.

enter image description here

s0xzwasd
  • 2,895
  • 3
  • 17
  • 26
0

I experienced this on my Debian machine and I wasn't using WSL2. I found that the actual cause of the issue is that Goland is unable to read the directory /usr/local/go/bin due to inadequate permission.

A possible solution is to run the goland.sh script as root. The script can be found in the bin/goland.sh directory of the Goland IDE folder. Here is a simple command to do run Goland as the root export HISTIGNORE='*sudo -S*' && echo "sudo-password-here" | sudo -S /absolute-path-to-goland.sh

export HISTIGNORE='*sudo -S*' tells bash history to ignore caching any command matching sudo -S* to bash history. This way, your sudo-password isn't saved into the bash-history file.

echo "sudo-password-here" | pipes your sudo password as input to the next command.

sudo -S tells bash to read input for password prompt from stdin, which has been provided through the echo command.

Alternatively, you can just install the latest version of Goland. Hopefully, it doesn't come with this bug

Ercross
  • 519
  • 6
  • 17