25

I'm using IntelliJ Idea, and the google-go-lang-idea-plugin from:

https://github.com/mtoader/google-go-lang-idea-plugin/issues/173

When I try to add my APT provided Go installation to the Go SDK list, I get the following error

The selected directory is not a valid home for Go Sdk

I have tried adding the following directories as the Go SDK root

  • /usr/share/go/
  • /usr/share/src/
  • /usr/lib/go/
  • /usr/lib/go/src/
  • /usr/lib/go/pkg/
  • /usr/lib/go/pkg/linux_amd64

Does anyone know how to get this working? I've commented on the various issues in the bugtracker, however the maintainer claimed that this was fixed 10 months ago.

Failing that, does anyone know what this plugin is actually looking for that would make a directory look like the SDK directory?

Thomas
  • 11,757
  • 4
  • 41
  • 57

8 Answers8

41

I came this issue when config goroot path in goland idea.

enter image description here I solve it as follows,

Go the GO SDK path and find zversion.go, then append the file with

const TheVersion = `go1.17.2`

. You need to change the version according to you case.

In my case the sversion.go path is located at D:\Programs\Go\src\runtime\internal\sys\zversion.go.

Save the file, and restart the goland ide, then config the GOROOT (File -> setting -> Go -> GOROOT -> + -> local...), select you Go root path and save it.

enter image description here

Vega
  • 27,856
  • 27
  • 95
  • 103
LF00
  • 27,015
  • 29
  • 156
  • 295
5

addon: got the same problem on go1.18.4, just need to add this line of code in ${GOROOT}/src/runtime/internal/sys/zversion.go

const TheVersion = `go1.18`
Flybywind
  • 968
  • 1
  • 11
  • 23
3

It turns out that google-go-lang-idea-plugin requires a slightly different folder structure than the default apt install produces. To fix it:

# mkdir /usr/lib/go/bin
# ln -s /usr/bin/go    /usr/lib/go/bin/go
# ln -s /usr/bin/godoc /usr/lib/go/bin/godoc
# ln -s /usr/bin/gofmt /usr/lib/go/bin/gofmt
Thomas
  • 11,757
  • 4
  • 41
  • 57
  • This is not required anymore since the v1.0.0 of the plugin, as such, please don't mess around with the system paths and report any issues to the bug tracker in order to improve it. Thank you. – dlsniper Mar 10 '15 at 19:29
  • The v1.0.0 is still in alpha and I can't install it with PhpStorm version 8, what do you suggest then? thanks – cirpo Apr 11 '15 at 19:25
  • @cirpo you can use either PHPStorm 9 EAP or IntelliJ IDEA Community 14.1+ (which is free). – dlsniper Apr 15 '15 at 22:39
2

Step 1: Open cmd

Step 2: Run below command => go env

Step 3: Find GOROOT and according this GOROOT path select directory for Go Sdk.

  • 1
    This is very simple, and it works. I am on a Mac, installed Go through Homebrew, and was trying to get GoLand to recognize it. This was all it took. – greymatter Jun 13 '22 at 22:08
1

So I just had this exact problem on IntelliJ 2016.1.3 with Go 1.5.

I had installed the IntelliJ Go Plugin a while ago and installed GO 1.5 a while back, and it all worked fine. Now i checked and suddenly, I'm sure I didn't remove it, GO 1.5 was gone from my system. But who knows, I haven't worked with go for a bit, so I might have removed it.

Anyway, after a bit of debugging, the following steps helped me:

  1. Install the most current Go version (currently for me 1.6.3). Follow the instructions on https://golang.org/doc/install
  2. Update the Plugin for Go in IntelliJ !!!
  3. Set the SDK in IntelliJ for the project:File -> Project Structure -> Project -> under Project SDK add a New SDK and navigate to your go installation.
  4. Click Apply and then Ok
flamingo
  • 349
  • 3
  • 8
1

I met the same problem when using go1.18 and add

const TheVersion = `go1.18`

in /src/runtime/internal/sys/zversion.go under GOROOT PATH

but it didn't work. Similar action for go1.17, it worked.

Jing Wang
  • 31
  • 5
0

goland 2022.3.2 golang 1.19.5

The IDE will check the following items when adding goSDK 1、dir/bin/go.exe exists? 2、dir/bin/go.exe can execute? 3、dir/VERSION

dir/src/runtime/internal/sys/zversion.go don't change

fured
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 24 '23 at 13:02
0

As the answer above said, goland checks three items when adding go sdk. I got the similar situation because i renamed the 'go' command to 'go20' in bin directory, for keeping multi versions of go environments. The problem was solved by adding version val into the file and saving two executable commands 'go' and 'go20' and just add go20 into the system path, made goland could find the initial go command. If your problem still exists after adding the var, check the bin directory.

jjyt
  • 1
  • 1