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?

10 Answers 10

44

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

5
  • 1
    hey dude,you saved my day! i just edit your answer to fix some markdown syntax and added a hyperlink i found in jetbrains
    – kajibu
    Commented Nov 2, 2021 at 11:58
  • 1
    Works like charm!
    – Volvox
    Commented Nov 9, 2021 at 23:58
  • No clue why this would work, but it does
    – Adam
    Commented Mar 7, 2022 at 19:44
  • Seems it doesn't work on 2022.1.3 now. :-(
    – MewX
    Commented Jul 13, 2022 at 11:45
  • works for 1.19.3 too Commented Dec 12, 2022 at 6:49
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`
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
3
  • 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
    Commented Mar 10, 2015 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
    Commented Apr 11, 2015 at 19:25
  • @cirpo you can use either PHPStorm 9 EAP or IntelliJ IDEA Community 14.1+ (which is free).
    – dlsniper
    Commented Apr 15, 2015 at 22:39
3

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
  • 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
    Commented Jun 13, 2022 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
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.

1
  • But it works for go1.18.3 so i used go1.18.3
    – Jing Wang
    Commented Aug 19, 2022 at 3:22
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

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.
    – Community Bot
    Commented May 24, 2023 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.

0
  1. Open your comand-line and type:

    go env
    
  2. Then find the set GOROOT= section and go to the directory which specified after "=" sign.

  3. Navigate to the directory src\runtime\internal\sys then find the zversoin.go file and open it by a text editor opened by run as administrator mode.

  4. Append the blow code by end of the file and save:

    const TheVesion = `go{version of go e.g. 1.20}`
    

Note: Use a backtilde, not a single quote for go{version of Go, e.g., 1.20}.

  1. Close and reopen you IDE and the try again(i.e. go to GOROOT folder retrived by go env command).

  2. For further information refer to, GOROOT and GOPATH configuration.

0

Make sure you have installed the latest version of Goland. Also, if you encountered this issue on mac, make sure you have the correct go installation for your CPU.

Not the answer you're looking for? Browse other questions tagged or ask your own question.